Mercurial > emacs
comparison lisp/emacs-lisp/lisp-mode.el @ 65851:c9b01535e163
(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.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Wed, 05 Oct 2005 15:03:09 +0000 |
parents | e7b6d13be107 |
children | 4b5af439906f |
comparison
equal
deleted
inserted
replaced
65850:125c8f7cc7d2 | 65851:c9b01535e163 |
---|---|
145 ;; define-global-mode has no explicit docstring. | 145 ;; define-global-mode has no explicit docstring. |
146 (put 'easy-mmode-define-global-mode 'doc-string-elt 0) | 146 (put 'easy-mmode-define-global-mode 'doc-string-elt 0) |
147 (put 'define-ibuffer-filter 'doc-string-elt 2) | 147 (put 'define-ibuffer-filter 'doc-string-elt 2) |
148 (put 'define-ibuffer-op 'doc-string-elt 3) | 148 (put 'define-ibuffer-op 'doc-string-elt 3) |
149 (put 'define-ibuffer-sorter 'doc-string-elt 2) | 149 (put 'define-ibuffer-sorter 'doc-string-elt 2) |
150 (put 'lambda 'doc-string-elt 2) | |
151 | |
152 (defvar lisp-doc-string-elt-property 'doc-string-elt | |
153 "The symbol property that holds the docstring position info.") | |
150 | 154 |
151 (defun lisp-font-lock-syntactic-face-function (state) | 155 (defun lisp-font-lock-syntactic-face-function (state) |
152 (if (nth 3 state) | 156 (if (nth 3 state) |
153 (if (and (eq (nth 0 state) 1) | 157 ;; This might be a docstring. |
154 ;; This might be a docstring. | 158 (let* ((listbeg (nth 1 state)) |
155 (save-excursion | 159 (firstsym (and listbeg |
156 (let ((n 0)) | 160 (save-excursion |
157 (goto-char (nth 8 state)) | 161 (goto-char listbeg) |
158 (condition-case nil | 162 (and (looking-at "([ \t\n]*\\(\\(\\sw\\|\\s_\\)+\\)") |
159 (while (and (not (bobp)) | 163 (match-string 1))))) |
160 (progn (backward-sexp 1) (setq n (1+ n))))) | 164 (docelt (and firstsym (get (intern-soft firstsym) |
161 (scan-error nil)) | 165 lisp-doc-string-elt-property)))) |
162 (when (> n 0) | 166 (if (and docelt |
163 (let ((sym (intern-soft | 167 ;; It's a string passed to a macro that has docstrings. |
164 (buffer-substring | 168 ;; Check whether it's in docstring position. |
165 (point) (progn (forward-sexp 1) (point)))))) | 169 (let ((startpos (nth 8 state))) |
166 (eq n (get sym 'doc-string-elt))))))) | 170 (save-excursion |
167 font-lock-doc-face | 171 (when (functionp docelt) |
168 font-lock-string-face) | 172 (goto-char (match-end 1)) |
173 (setq docelt (funcall docelt))) | |
174 (goto-char listbeg) | |
175 (forward-char 1) | |
176 (condition-case nil | |
177 (while (and (> docelt 0) (< (point) startpos) | |
178 (progn (forward-sexp 1) t)) | |
179 (setq docelt (1- docelt))) | |
180 (error nil)) | |
181 (and (zerop docelt) (<= (point) startpos) | |
182 (progn (forward-comment (point-max)) t) | |
183 (= (point) (nth 8 state)))))) | |
184 font-lock-doc-face | |
185 font-lock-string-face)) | |
169 font-lock-comment-face)) | 186 font-lock-comment-face)) |
170 | 187 |
171 ;; The LISP-SYNTAX argument is used by code in inf-lisp.el and is | 188 ;; The LISP-SYNTAX argument is used by code in inf-lisp.el and is |
172 ;; (uselessly) passed from pp.el, chistory.el, gnus-kill.el and score-mode.el | 189 ;; (uselessly) passed from pp.el, chistory.el, gnus-kill.el and score-mode.el |
173 (defun lisp-mode-variables (&optional lisp-syntax) | 190 (defun lisp-mode-variables (&optional lisp-syntax) |