]> git.eshelyaron.com Git - emacs.git/commitdiff
Add `add-log-current-defun-function's for CSS and HTML mode.
authorJari Aalto <jari.aalto@cante.net>
Sat, 1 Dec 2012 05:51:33 +0000 (13:51 +0800)
committerChong Yidong <cyd@gnu.org>
Sat, 1 Dec 2012 05:51:33 +0000 (13:51 +0800)
* 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.

lisp/ChangeLog
lisp/textmodes/css-mode.el
lisp/textmodes/sgml-mode.el

index c7fb5cabe0744c40161f1edc2e74165708e31484..c2e5e9fa8ce9a792c2031f4ca01ad2b69b64b894 100644 (file)
@@ -1,3 +1,11 @@
+2012-12-01  Jari Aalto  <jari.aalto@cante.net>
+
+       * 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  <cyd@gnu.org>
 
        Modularize add-log-current-defun (Bug#2224).
index ba104e7b39410d0f7ecae651454c52e7f85f1e2e..7130e1c9cee56814ddca7a73aee7e6ca5a6d752e 100644 (file)
   (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)
           (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
index 820822222afe18a1dfd1893e9fb128d94aa1b502..97faa3afb36c6d71681958a55ea729e620628e32 100644 (file)
@@ -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))))
+
 \f
 ;;;###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 "</[Hh][1-6]>")
   (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)