Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of http://github.com/pft/elisp-assorted

Conflicts:
	css-check.el
  • Loading branch information...
commit 3d9fe2d06e00ae084163e386eb707da921a6662d 2 parents ccb1c7d + 6c30be9
Niels Giesen authored
Showing with 199 additions and 106 deletions.
  1. +199 −106 css-check.el
305 css-check.el
View
@@ -1,107 +1,200 @@
-;;; css-complete.el --- complete css attributes and properties
-
-;; Copyright (C) 2010 niels giesen
-
-;; Author: Niels Giesen <com dot gmail at niels dot giesen, in reversed order>
-;; Website: http://pft.github.com
-;; Keywords: css, web, html
-
-;; This program is free software; you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License
-;; as published by the Free Software Foundation; either version 3
-;; of the License, or (at your option) any later version.
-
-;; This program is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with this program; if not, write to the Free Software
-;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-;; 02110-1301, USA.
-
-;;; Commentary:
-
-;; Quick program. Use csstidy to check buffer for improper css.
-
-;;; Usage:
-
-;; M-x css-check to check buffer using the minifying program csstidy.
-
-;;; Code:
-
-(defvar css-file nil)
-
-(defvar css-check-map
- (let ((map (make-sparse-keymap)))
- (define-key map "\C-m" 'css-check-goto-line-at-p)
- (define-key map "f" 'css-check-toggle-follow)
- (define-key map "j" 'css-check-next-line)
- (define-key map "k" 'css-check-prev-line)
- (define-key map [(mouse-1)] 'css-check-goto-line-at-p)
- map))
-
-(defvar css-check-follow-mode nil)
-
-(defun css-check-toggle-follow ()
- (interactive)
- (setq css-check-follow-mode
- (not css-check-follow-mode)))
-
-(defun css-check-next-line ()
- (interactive)
- (forward-line 1)
- (when css-check-follow-mode
- (let ((buffer (current-buffer)))
- (css-check-goto-line-at-p)
- (switch-to-buffer-other-window buffer))))
-
-(defun css-check-prev-line ()
- (interactive)
- (forward-line -1)
- (when css-check-follow-mode
- (let ((buffer (current-buffer)))
- (css-check-goto-line-at-p)
- (switch-to-buffer-other-window buffer))))
-
-(defun css-check-goto-line-at-p ()
- (interactive)
- (and css-file
- (let ((line
- (save-excursion
- (beginning-of-line)
- (save-match-data
- (and (re-search-forward "^[[:digit:]]+"
- (point-at-eol) t)
- (string-to-number (match-string 0)))))))
- (find-file-other-window css-file)
- (and line
- (goto-line line)))))
-
-(defun css-check ()
- (interactive)
- (let* ((file (buffer-file-name))
- (cmd (format "csstidy %s /dev/null" file))
- (res (shell-command-to-string cmd)))
- (switch-to-buffer "*css-check*")
- (let (buffer-read-only)
- (erase-buffer)
- (insert res)
- (goto-char (point-min))
- (while (re-search-forward "^[[:digit:]]+" nil t)
- (put-text-property (match-beginning 0)
- (match-end 0)
- 'mouse-face 'highlight
- )
- (put-text-property (match-beginning 0)
- (match-end 0)
- 'keymap 'highlight
- ))
- (goto-char (point-min))
- (forward-line 5)
- (setq css-file file)
- (use-local-map css-check-map))
- (setq buffer-read-only t)))
-
+;;; css-complete.el --- complete css attributes and properties
+
+;; Copyright (C) 2010 niels giesen
+
+;; Author: Niels Giesen <com dot gmail at niels dot giesen, in reversed order>
+;; Website: http://pft.github.com
+;; Keywords: css, web, html
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License
+;; as published by the Free Software Foundation; either version 3
+;; of the License, or (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program; if not, write to the Free Software
+;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+;; 02110-1301, USA.
+
+;;; Commentary:
+
+;; Quick program. Use csstidy to check buffer for improper css.
+
+;;; Usage:
+
+;; M-x css-check to check buffer using the minifying program csstidy.
+
+;;; Code:
+
+(defvar css-file nil)
+
+(defgroup css-check nil
+ "Customization group for CSS-check"
+ :group 'css)
+
+(defface css-check-unapplied-face
+ '((default)
+ (((background light)) (:foreground "#ab5736"))
+ (((background dark)) (:foreground "#ab5736")))
+ "Face for unapplied line."
+ :group 'css-check)
+
+(defface css-check-applied-face
+ '((default)
+ (((background light)) (:foreground "#aa9b37"))
+ (((background dark)) (:foreground "#aa9b37")))
+ "Face for applied line."
+ :group 'css-check)
+
+(defvar css-check-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map "\C-m" 'css-check-goto-line-at-p)
+ (define-key map "f" 'css-check-toggle-follow)
+ (define-key map "j" 'css-check-next-line)
+ (define-key map "k" 'css-check-prev-line)
+ (define-key map "a" 'css-check-apply-line-at-p)
+ (define-key map "u" 'css-check-undo-application-at-p)
+ map))
+
+(defvar css-check-follow-mode nil)
+
+(defun css-check-toggle-follow ()
+ (interactive)
+ (setq css-check-follow-mode
+ (not css-check-follow-mode)))
+
+(defun css-check-next-line ()
+ (interactive)
+ (forward-line 1)
+ (when css-check-follow-mode
+ (let ((buffer (current-buffer)))
+ (css-check-goto-line-at-p)
+ (switch-to-buffer-other-window buffer))))
+
+(defun css-check-prev-line ()
+ (interactive)
+ (forward-line -1)
+ (when css-check-follow-mode
+ (let ((buffer (current-buffer)))
+ (css-check-goto-line-at-p)
+ (switch-to-buffer-other-window buffer))))
+
+(defun css-check-goto-line-at-p ()
+ (interactive)
+ (and css-file
+ (let ((line
+ (save-excursion
+ (beginning-of-line)
+ (save-match-data
+ (and (re-search-forward "^[[:digit:]]+"
+ (point-at-eol) t)
+ (string-to-number (match-string 0)))))))
+ (find-file-other-window css-file)
+ (and line
+ (goto-line line)))))
+
+(defun css-check-apply-line-at-p ()
+ "Apply tidying at point."
+ (interactive)
+ (if (text-property-any (point-at-bol)
+ (1+ (point-at-bol))
+ 'face
+ 'css-check-applied-face)
+ (message "Line has already been applied")
+ (let ((buffer (current-buffer)))
+ (multiple-value-bind (oldtext newtext)
+ (save-excursion
+ (end-of-line)
+ (re-search-backward "Changed \"\\([^\"]+\\)\" to \"\\([^\"]+\\)\"$"
+ (point-at-bol) t)
+ (values
+ (match-string 1)
+ (match-string 2)))
+ (when (and oldtext newtext)
+ (css-check-goto-line-at-p)
+ (save-excursion
+ (replace-string oldtext newtext nil (point-at-bol) (point-at-eol)))
+ (switch-to-buffer-other-window buffer)
+ (save-excursion
+ (let (buffer-read-only)
+ (put-text-property
+ (point-at-bol)
+ (progn
+ (beginning-of-line)
+ (re-search-forward "^[[:digit:]]+"
+ (point-at-eol)
+ t)
+ (point))
+ 'face 'css-check-applied-face))))))))
+
+(defun css-check-undo-application-at-p ()
+ "Undo application at point."
+ (interactive)
+ (if (text-property-any (point-at-bol)
+ (1+ (point-at-bol))
+ 'face
+ 'css-check-unapplied-face)
+ (message "Line has not been applied")
+ (let ((buffer (current-buffer)))
+ (multiple-value-bind (newtext oldtext)
+ (save-excursion
+ (end-of-line)
+ (re-search-backward "Changed \"\\([^\"]+\\)\" to \"\\([^\"]+\\)\"$"
+ (point-at-bol) t)
+ (values
+ (match-string 1)
+ (match-string 2)))
+ (when (and oldtext newtext)
+ (css-check-goto-line-at-p)
+ (save-excursion
+ (replace-string oldtext newtext nil (point-at-bol) (point-at-eol)))
+ (switch-to-buffer-other-window buffer)
+ (save-excursion
+ (let (buffer-read-only)
+ (put-text-property
+ (point-at-bol)
+ (progn
+ (beginning-of-line)
+ (re-search-forward "^[[:digit:]]+"
+ (point-at-eol)
+ t)
+ (point))
+ 'face 'css-check-unapplied-face))))))))
+
+(defun css-check ()
+ (interactive)
+ (and
+ (buffer-modified-p)
+ (y-or-n-p
+ (format "Buffer %s has been modified since last save. Save buffer? "
+ (current-buffer)))
+ (save-buffer))
+ (let* ((file (buffer-file-name))
+ (cmd (format "csstidy %s /dev/null" file))
+ (res (shell-command-to-string cmd)))
+ (switch-to-buffer "*css-check*")
+ (let (buffer-read-only)
+ (erase-buffer)
+ (insert res)
+ (goto-char (point-min))
+ (while (re-search-forward "^[[:digit:]]+" nil t)
+ (put-text-property (match-beginning 0)
+ (match-end 0)
+ 'face 'css-check-unapplied-face)
+ (put-text-property (match-beginning 0)
+ (match-end 0)
+ 'keymap 'highlight
+ ))
+ (goto-char (point-min))
+ (forward-line 5)
+ (setq css-file file)
+ (use-local-map css-check-map))
+ (setq buffer-read-only t)))
+
+(provide 'css-check)
;; css-check.el ends here
Please sign in to comment.
Something went wrong with that request. Please try again.