comparison lisp/help.el @ 28841:354a826d7b20

(describe-variable): Have customize button pop the help-xref stack when invoked. (help-xref-symbol-regexp): Add `face'. (help-make-xrefs): Check for quoted face names and adapt regexp submatch numbers to cope. (help-xref-interned): Maybe insert face doc too. Separate sections with a line of hyphens.
author Dave Love <fx@gnu.org>
date Tue, 09 May 2000 15:50:39 +0000
parents 383f9592d9dd
children 43d9eb93e1fb
comparison
equal deleted inserted replaced
28840:d0531e35d9f2 28841:354a826d7b20
856 (princ (concat "You can " customize-label " this variable.")) 856 (princ (concat "You can " customize-label " this variable."))
857 (with-current-buffer "*Help*" 857 (with-current-buffer "*Help*"
858 (save-excursion 858 (save-excursion
859 (re-search-backward 859 (re-search-backward
860 (concat "\\(" customize-label "\\)") nil t) 860 (concat "\\(" customize-label "\\)") nil t)
861 (help-xref-button 1 #'(lambda (v) 861 (help-xref-button 1 (lambda (v)
862 (customize-variable v)) 862 (if help-xref-stack
863 (pop help-xref-stack))
864 (customize-variable v))
863 variable 865 variable
864 "mouse-2, RET: customize variable") 866 "mouse-2, RET: customize variable")))))
865 ))))
866 ;; Make a hyperlink to the library if appropriate. (Don't 867 ;; Make a hyperlink to the library if appropriate. (Don't
867 ;; change the format of the buffer's initial line in case 868 ;; change the format of the buffer's initial line in case
868 ;; anything expects the current format.) 869 ;; anything expects the current format.)
869 (let ((file-name (symbol-file variable))) 870 (let ((file-name (symbol-file variable)))
870 (when file-name 871 (when file-name
1012 "Label to use by `help-make-xrefs' for the go-back reference.") 1013 "Label to use by `help-make-xrefs' for the go-back reference.")
1013 1014
1014 (defconst help-xref-symbol-regexp 1015 (defconst help-xref-symbol-regexp
1015 (purecopy (concat "\\(\\<\\(\\(variable\\|option\\)\\|" 1016 (purecopy (concat "\\(\\<\\(\\(variable\\|option\\)\\|"
1016 "\\(function\\|command\\)\\|" 1017 "\\(function\\|command\\)\\|"
1018 "\\(face\\)\\|"
1017 "\\(symbol\\)\\)\\s-+\\)?" 1019 "\\(symbol\\)\\)\\s-+\\)?"
1018 ;; Note starting with word-syntax character: 1020 ;; Note starting with word-syntax character:
1019 "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'")) 1021 "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'"))
1020 "Regexp matching doc string references to symbols. 1022 "Regexp matching doc string references to symbols.
1021 1023
1075 (help-xref-button 1 #'info data 1077 (help-xref-button 1 #'info data
1076 "mouse-2, RET: read this Info node")))) 1078 "mouse-2, RET: read this Info node"))))
1077 ;; Quoted symbols 1079 ;; Quoted symbols
1078 (save-excursion 1080 (save-excursion
1079 (while (re-search-forward help-xref-symbol-regexp nil t) 1081 (while (re-search-forward help-xref-symbol-regexp nil t)
1080 (let* ((data (match-string 6)) 1082 (let* ((data (match-string 7))
1081 (sym (intern-soft data))) 1083 (sym (intern-soft data)))
1082 (if sym 1084 (if sym
1083 (cond 1085 (cond
1084 ((match-string 3) ; `variable' &c 1086 ((match-string 3) ; `variable' &c
1085 (and (boundp sym) ; `variable' doesn't ensure 1087 (and (boundp sym) ; `variable' doesn't ensure
1086 ; it's actually bound 1088 ; it's actually bound
1087 (help-xref-button 1089 (help-xref-button
1088 6 #'describe-variable sym 1090 7 #'describe-variable sym
1089 "mouse-2, RET: describe this variable"))) 1091 "mouse-2, RET: describe this variable")))
1090 ((match-string 4) ; `function' &c 1092 ((match-string 4) ; `function' &c
1091 (and (fboundp sym) ; similarly 1093 (and (fboundp sym) ; similarly
1092 (help-xref-button 1094 (help-xref-button
1093 6 #'describe-function sym 1095 7 #'describe-function sym
1094 "mouse-2, RET: describe this function"))) 1096 "mouse-2, RET: describe this function")))
1095 ((match-string 5)) ; nothing for symbol 1097 ((match-string 5) ; `face'
1098 (and (facep sym)
1099 (help-xref-button 7 #'describe-face sym
1100 "mouse-2, RET: describe this face")))
1101 ((match-string 6)) ; nothing for symbol
1096 ((and (boundp sym) (fboundp sym)) 1102 ((and (boundp sym) (fboundp sym))
1097 ;; We can't intuit whether to use the 1103 ;; We can't intuit whether to use the
1098 ;; variable or function doc -- supply both. 1104 ;; variable or function doc -- supply both.
1099 (help-xref-button 1105 (help-xref-button
1100 6 #'help-xref-interned sym 1106 7 #'help-xref-interned sym
1101 "mouse-2, RET: describe this symbol")) 1107 "mouse-2, RET: describe this symbol"))
1102 ((boundp sym) 1108 ((boundp sym)
1103 (help-xref-button 1109 (help-xref-button
1104 6 #'describe-variable sym 1110 7 #'describe-variable sym
1105 "mouse-2, RET: describe this variable")) 1111 "mouse-2, RET: describe this variable"))
1106 ((fboundp sym) 1112 ((fboundp sym)
1107 (help-xref-button 1113 (help-xref-button
1108 6 #'describe-function sym 1114 7 #'describe-function sym
1109 "mouse-2, RET: describe this function"))))))) 1115 "mouse-2, RET: describe this function"))
1116 ((facep sym)
1117 (help-xref-button
1118 7 #'describe-face sym)))))))
1110 ;; An obvious case of a key substitution: 1119 ;; An obvious case of a key substitution:
1111 (save-excursion 1120 (save-excursion
1112 (while (re-search-forward 1121 (while (re-search-forward
1113 ;; Assume command name is only word characters 1122 ;; Assume command name is only word characters
1114 ;; and dashes to get things like `use M-x foo.'. 1123 ;; and dashes to get things like `use M-x foo.'.
1192 (defun help-xref-interned (symbol) 1201 (defun help-xref-interned (symbol)
1193 "Follow a hyperlink which appeared to be an arbitrary interned SYMBOL. 1202 "Follow a hyperlink which appeared to be an arbitrary interned SYMBOL.
1194 1203
1195 Both variable and function documentation are extracted into a single 1204 Both variable and function documentation are extracted into a single
1196 help buffer." 1205 help buffer."
1197 (let ((fdoc (when (fboundp symbol) (describe-function symbol)))) 1206 (let ((fdoc (when (fboundp symbol) (describe-function symbol)))
1207 (facedoc (when (facep symbol) (describe-face symbol))))
1198 (when (or (boundp symbol) (not fdoc)) 1208 (when (or (boundp symbol) (not fdoc))
1199 (describe-variable symbol) 1209 (describe-variable symbol)
1200 ;; We now have a help buffer on the variable. Insert the function 1210 ;; We now have a help buffer on the variable. Insert the function
1201 ;; text before it. 1211 ;; text before it.
1202 (when fdoc 1212 (when (or fdoc facedoc)
1203 (with-current-buffer "*Help*" 1213 (with-current-buffer "*Help*"
1204 (goto-char (point-min)) 1214 (goto-char (point-min))
1205 (let ((inhibit-read-only t)) 1215 (let ((inhibit-read-only t))
1206 (insert fdoc "\n\n" (symbol-name symbol) " is also a variable.\n\n")) 1216 (when fdoc
1217 (insert fdoc "\n\n"))
1218 (when facedoc
1219 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
1220 " is also a " "face." "\n\n" facedoc "\n\n"))
1221 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
1222 " is also a " "variable." "\n\n"))
1207 (help-setup-xref (list #'help-xref-interned symbol) nil)))))) 1223 (help-setup-xref (list #'help-xref-interned symbol) nil))))))
1208 1224
1209 (defun help-xref-mode (buffer) 1225 (defun help-xref-mode (buffer)
1210 "Do a `describe-mode' for the specified BUFFER." 1226 "Do a `describe-mode' for the specified BUFFER."
1211 (save-excursion 1227 (save-excursion