summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2005-10-05 15:03:09 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2005-10-05 15:03:09 +0000
commitebf0903558b67232fb2f1f3f2921c7141833d2de (patch)
treed0c721ea912fa9a6b0f25a9a6930e85e3ec6c72b /lisp/emacs-lisp
parent9903dbc404a0d169d33d310abf65c8bee5359b67 (diff)
downloademacs-ebf0903558b67232fb2f1f3f2921c7141833d2de.tar.gz
(lambda): Add its doc-string-elt property.
(lisp-doc-string-elt-property): New var. (lisp-font-lock-syntactic-face-function): Use it. Rewrite to recognize docstrings even for forms not at toplevel.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/lisp-mode.el49
1 files changed, 33 insertions, 16 deletions
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index b347c136adf..c9786ad68d3 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -147,25 +147,42 @@
(put 'define-ibuffer-filter 'doc-string-elt 2)
(put 'define-ibuffer-op 'doc-string-elt 3)
(put 'define-ibuffer-sorter 'doc-string-elt 2)
+(put 'lambda 'doc-string-elt 2)
+
+(defvar lisp-doc-string-elt-property 'doc-string-elt
+ "The symbol property that holds the docstring position info.")
(defun lisp-font-lock-syntactic-face-function (state)
(if (nth 3 state)
- (if (and (eq (nth 0 state) 1)
- ;; This might be a docstring.
- (save-excursion
- (let ((n 0))
- (goto-char (nth 8 state))
- (condition-case nil
- (while (and (not (bobp))
- (progn (backward-sexp 1) (setq n (1+ n)))))
- (scan-error nil))
- (when (> n 0)
- (let ((sym (intern-soft
- (buffer-substring
- (point) (progn (forward-sexp 1) (point))))))
- (eq n (get sym 'doc-string-elt)))))))
- font-lock-doc-face
- font-lock-string-face)
+ ;; This might be a docstring.
+ (let* ((listbeg (nth 1 state))
+ (firstsym (and listbeg
+ (save-excursion
+ (goto-char listbeg)
+ (and (looking-at "([ \t\n]*\\(\\(\\sw\\|\\s_\\)+\\)")
+ (match-string 1)))))
+ (docelt (and firstsym (get (intern-soft firstsym)
+ lisp-doc-string-elt-property))))
+ (if (and docelt
+ ;; It's a string passed to a macro that has docstrings.
+ ;; Check whether it's in docstring position.
+ (let ((startpos (nth 8 state)))
+ (save-excursion
+ (when (functionp docelt)
+ (goto-char (match-end 1))
+ (setq docelt (funcall docelt)))
+ (goto-char listbeg)
+ (forward-char 1)
+ (condition-case nil
+ (while (and (> docelt 0) (< (point) startpos)
+ (progn (forward-sexp 1) t))
+ (setq docelt (1- docelt)))
+ (error nil))
+ (and (zerop docelt) (<= (point) startpos)
+ (progn (forward-comment (point-max)) t)
+ (= (point) (nth 8 state))))))
+ font-lock-doc-face
+ font-lock-string-face))
font-lock-comment-face))
;; The LISP-SYNTAX argument is used by code in inf-lisp.el and is