From: Jari Aalto Date: Sat, 1 Dec 2012 05:51:33 +0000 (+0800) Subject: Add `add-log-current-defun-function's for CSS and HTML mode. X-Git-Tag: emacs-24.3.90~173^2~9^2~106 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f38cd76e55fd04f0386859cede6f876c1bd1620d;p=emacs.git Add `add-log-current-defun-function's for CSS and HTML mode. * textmodes/css-mode.el (css-current-defun-name): New function. (css-mode): Use it. * textmodes/sgml-mode.el (html-current-defun-name): New function. (html-mode): Use it. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c7fb5cabe07..c2e5e9fa8ce 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2012-12-01 Jari Aalto + + * textmodes/css-mode.el (css-current-defun-name): New function. + (css-mode): Use it. + + * textmodes/sgml-mode.el (html-current-defun-name): New function. + (html-mode): Use it. + 2012-12-01 Chong Yidong Modularize add-log-current-defun (Bug#2224). diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index ba104e7b394..7130e1c9cee 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -275,6 +275,7 @@ (setq-local parse-sexp-ignore-comments t) (setq-local indent-line-function 'css-indent-line) (setq-local fill-paragraph-function 'css-fill-paragraph) + (setq-local add-log-current-defun-function #'css-current-defun-name) (when css-electric-keys (let ((fc (make-char-table 'auto-fill-chars))) (set-char-table-parent fc auto-fill-chars) @@ -480,5 +481,15 @@ (save-excursion (indent-line-to indent)) (indent-line-to indent))))) +(defun css-current-defun-name () + "Return the name of the CSS section at point, or nil." + (save-excursion + (let ((max (max (point-min) (- (point) 1600)))) ; approx 20 lines back + (when (search-backward "{" max t) + (skip-chars-backward " \t\r\n") + (beginning-of-line) + (if (looking-at "^[ \t]*\\([^{\r\n]*[^ {\t\r\n]\\)") + (match-string-no-properties 1)))))) + (provide 'css-mode) ;;; css-mode.el ends here diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el index 820822222af..97faa3afb36 100644 --- a/lisp/textmodes/sgml-mode.el +++ b/lisp/textmodes/sgml-mode.el @@ -1932,6 +1932,19 @@ This takes effect when first loading the library.") (defvar outline-heading-end-regexp) (defvar outline-level) +(defun html-current-defun-name () + "Return the name of the last HTML title or heading, or nil." + (save-excursion + (if (re-search-backward + (concat + "<[ \t\r\n]*" + "\\(?:[hH][0-6]\\|title\\|TITLE\\|Title\\)" + "[^>]*>" + "[ \t\r\n]*" + "\\([^<\r\n]*[^ <\t\r\n]+\\)") + nil t) + (match-string-no-properties 1)))) + ;;;###autoload (define-derived-mode html-mode sgml-mode '(sgml-xml-mode "XHTML" "HTML") @@ -1979,6 +1992,7 @@ To work around that, do: (setq-local outline-heading-end-regexp "") (setq-local outline-level (lambda () (char-before (match-end 0)))) + (setq-local add-log-current-defun-function #'html-current-defun-name) (setq-local sentence-end-base "[.?!][]\"'”)}]*\\(<[^>]*>\\)*") (setq imenu-create-index-function 'html-imenu-index)