diff options
| author | Stefan Monnier | 2005-10-05 15:03:09 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2005-10-05 15:03:09 +0000 |
| commit | f8ab194748b1293ab97bc45f8a5519fa9acce569 (patch) | |
| tree | 5249bf71fb94f5c5fafca208cd05af7e4d3cea0c | |
| parent | f17ae68f2a52e51d304480e4e8ce1d1e6385f401 (diff) | |
| download | emacs-f8ab194748b1293ab97bc45f8a5519fa9acce569.tar.gz emacs-f8ab194748b1293ab97bc45f8a5519fa9acce569.zip | |
(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.
| -rw-r--r-- | lisp/emacs-lisp/lisp-mode.el | 49 |
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 @@ | |||
| 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 |