aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2014-03-13 20:32:41 -0400
committerGlenn Morris2014-03-13 20:32:41 -0400
commit56759cf12aeea9a51020ad19784d6ca6c55ab36e (patch)
treef4953bdcd987f8dbd9e4a41331c98c3cc1362090
parent7644aa970d350a7457ef2fba469c73bb00c22365 (diff)
downloademacs-56759cf12aeea9a51020ad19784d6ca6c55ab36e.tar.gz
emacs-56759cf12aeea9a51020ad19784d6ca6c55ab36e.zip
Move some help functions from help-fns.el to help.el, which is preloaded.
They are now needed by eg the function `documentation' in some circumstances. * lisp/help-fns.el (help-split-fundoc, help-add-fundoc-usage) (help-function-arglist, help-make-usage): Move from here... * lisp/help.el (help-split-fundoc, help-add-fundoc-usage) (help-function-arglist, help-make-usage): ... to here. * lisp/emacs-lisp/bytecomp.el (byte-compile-lambda): Do not load help-fns. Fixes: debbugs:17001
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/emacs-lisp/bytecomp.el1
-rw-r--r--lisp/help-fns.el103
-rw-r--r--lisp/help.el107
4 files changed, 115 insertions, 104 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e4dff0abd91..260a77fdca9 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12014-03-14 Glenn Morris <rgm@gnu.org>
2
3 * help-fns.el (help-split-fundoc, help-add-fundoc-usage)
4 (help-function-arglist, help-make-usage): Move from here...
5 * help.el (help-split-fundoc, help-add-fundoc-usage)
6 (help-function-arglist, help-make-usage): ... to here. (Bug#17001)
7 * emacs-lisp/bytecomp.el (byte-compile-lambda): Do not load help-fns.
8
12014-03-14 Juanma Barranquero <lekktu@gmail.com> 92014-03-14 Juanma Barranquero <lekktu@gmail.com>
2 10
3 * net/socks.el (socks, socks-override-functions) 11 * net/socks.el (socks, socks-override-functions)
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index e2e468717a6..e5f8a8cc22a 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -2706,7 +2706,6 @@ for symbols generated by the byte compiler itself."
2706 (cdr compiled) 2706 (cdr compiled)
2707 ;; optionally, the doc string. 2707 ;; optionally, the doc string.
2708 (cond (lexical-binding 2708 (cond (lexical-binding
2709 (require 'help-fns)
2710 (list (help-add-fundoc-usage doc arglist))) 2709 (list (help-add-fundoc-usage doc arglist)))
2711 ((or doc int) 2710 ((or doc int)
2712 (list doc))) 2711 (list doc)))
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index c772962f64b..a186254123d 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -69,109 +69,6 @@ The functions will receive the function name as argument.")
69 ;; Return the text we displayed. 69 ;; Return the text we displayed.
70 (buffer-string)))))) 70 (buffer-string))))))
71 71
72(defun help-split-fundoc (docstring def)
73 "Split a function DOCSTRING into the actual doc and the usage info.
74Return (USAGE . DOC) or nil if there's no usage info, where USAGE info
75is a string describing the argument list of DEF, such as
76\"(apply FUNCTION &rest ARGUMENTS)\".
77DEF is the function whose usage we're looking for in DOCSTRING."
78 ;; Functions can get the calling sequence at the end of the doc string.
79 ;; In cases where `function' has been fset to a subr we can't search for
80 ;; function's name in the doc string so we use `fn' as the anonymous
81 ;; function name instead.
82 (when (and docstring (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" docstring))
83 (cons (format "(%s%s"
84 ;; Replace `fn' with the actual function name.
85 (if (symbolp def) def "anonymous")
86 (match-string 1 docstring))
87 (unless (zerop (match-beginning 0))
88 (substring docstring 0 (match-beginning 0))))))
89
90;; FIXME: Move to subr.el?
91(defun help-add-fundoc-usage (docstring arglist)
92 "Add the usage info to DOCSTRING.
93If DOCSTRING already has a usage info, then just return it unchanged.
94The usage info is built from ARGLIST. DOCSTRING can be nil.
95ARGLIST can also be t or a string of the form \"(FUN ARG1 ARG2 ...)\"."
96 (unless (stringp docstring) (setq docstring ""))
97 (if (or (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" docstring)
98 (eq arglist t))
99 docstring
100 (concat docstring
101 (if (string-match "\n?\n\\'" docstring)
102 (if (< (- (match-end 0) (match-beginning 0)) 2) "\n" "")
103 "\n\n")
104 (if (and (stringp arglist)
105 (string-match "\\`([^ ]+\\(.*\\))\\'" arglist))
106 (concat "(fn" (match-string 1 arglist) ")")
107 (format "%S" (help-make-usage 'fn arglist))))))
108
109;; FIXME: Move to subr.el?
110(defun help-function-arglist (def &optional preserve-names)
111 "Return a formal argument list for the function DEF.
112IF PRESERVE-NAMES is non-nil, return a formal arglist that uses
113the same names as used in the original source code, when possible."
114 ;; Handle symbols aliased to other symbols.
115 (if (and (symbolp def) (fboundp def)) (setq def (indirect-function def)))
116 ;; If definition is a macro, find the function inside it.
117 (if (eq (car-safe def) 'macro) (setq def (cdr def)))
118 (cond
119 ((and (byte-code-function-p def) (listp (aref def 0))) (aref def 0))
120 ((eq (car-safe def) 'lambda) (nth 1 def))
121 ((eq (car-safe def) 'closure) (nth 2 def))
122 ((or (and (byte-code-function-p def) (integerp (aref def 0)))
123 (subrp def))
124 (or (when preserve-names
125 (let* ((doc (condition-case nil (documentation def) (error nil)))
126 (docargs (if doc (car (help-split-fundoc doc nil))))
127 (arglist (if docargs
128 (cdar (read-from-string (downcase docargs)))))
129 (valid t))
130 ;; Check validity.
131 (dolist (arg arglist)
132 (unless (and (symbolp arg)
133 (let ((name (symbol-name arg)))
134 (if (eq (aref name 0) ?&)
135 (memq arg '(&rest &optional))
136 (not (string-match "\\." name)))))
137 (setq valid nil)))
138 (when valid arglist)))
139 (let* ((args-desc (if (not (subrp def))
140 (aref def 0)
141 (let ((a (subr-arity def)))
142 (logior (car a)
143 (if (numberp (cdr a))
144 (lsh (cdr a) 8)
145 (lsh 1 7))))))
146 (max (lsh args-desc -8))
147 (min (logand args-desc 127))
148 (rest (logand args-desc 128))
149 (arglist ()))
150 (dotimes (i min)
151 (push (intern (concat "arg" (number-to-string (1+ i)))) arglist))
152 (when (> max min)
153 (push '&optional arglist)
154 (dotimes (i (- max min))
155 (push (intern (concat "arg" (number-to-string (+ 1 i min))))
156 arglist)))
157 (unless (zerop rest) (push '&rest arglist) (push 'rest arglist))
158 (nreverse arglist))))
159 ((and (autoloadp def) (not (eq (nth 4 def) 'keymap)))
160 "[Arg list not available until function definition is loaded.]")
161 (t t)))
162
163;; FIXME: Move to subr.el?
164(defun help-make-usage (function arglist)
165 (cons (if (symbolp function) function 'anonymous)
166 (mapcar (lambda (arg)
167 (if (not (symbolp arg)) arg
168 (let ((name (symbol-name arg)))
169 (cond
170 ((string-match "\\`&" name) arg)
171 ((string-match "\\`_" name)
172 (intern (upcase (substring name 1))))
173 (t (intern (upcase name)))))))
174 arglist)))
175 72
176;; Could be this, if we make symbol-file do the work below. 73;; Could be this, if we make symbol-file do the work below.
177;; (defun help-C-file-name (subr-or-var kind) 74;; (defun help-C-file-name (subr-or-var kind)
diff --git a/lisp/help.el b/lisp/help.el
index 1e3d41eb88a..46094e9f6b0 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -1222,6 +1222,113 @@ value in BODY."
1222 (if (stringp msg) 1222 (if (stringp msg)
1223 (with-output-to-temp-buffer " *Char Help*" 1223 (with-output-to-temp-buffer " *Char Help*"
1224 (princ msg))))) 1224 (princ msg)))))
1225
1226
1227;; The following functions used to be in help-fns.el, which is not preloaded.
1228;; But for various reasons, they are more widely needed, so they were
1229;; moved to this file, which is preloaded. http://debbugs.gnu.org/17001
1230
1231(defun help-split-fundoc (docstring def)
1232 "Split a function DOCSTRING into the actual doc and the usage info.
1233Return (USAGE . DOC) or nil if there's no usage info, where USAGE info
1234is a string describing the argument list of DEF, such as
1235\"(apply FUNCTION &rest ARGUMENTS)\".
1236DEF is the function whose usage we're looking for in DOCSTRING."
1237 ;; Functions can get the calling sequence at the end of the doc string.
1238 ;; In cases where `function' has been fset to a subr we can't search for
1239 ;; function's name in the doc string so we use `fn' as the anonymous
1240 ;; function name instead.
1241 (when (and docstring (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" docstring))
1242 (cons (format "(%s%s"
1243 ;; Replace `fn' with the actual function name.
1244 (if (symbolp def) def "anonymous")
1245 (match-string 1 docstring))
1246 (unless (zerop (match-beginning 0))
1247 (substring docstring 0 (match-beginning 0))))))
1248
1249(defun help-add-fundoc-usage (docstring arglist)
1250 "Add the usage info to DOCSTRING.
1251If DOCSTRING already has a usage info, then just return it unchanged.
1252The usage info is built from ARGLIST. DOCSTRING can be nil.
1253ARGLIST can also be t or a string of the form \"(FUN ARG1 ARG2 ...)\"."
1254 (unless (stringp docstring) (setq docstring ""))
1255 (if (or (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" docstring)
1256 (eq arglist t))
1257 docstring
1258 (concat docstring
1259 (if (string-match "\n?\n\\'" docstring)
1260 (if (< (- (match-end 0) (match-beginning 0)) 2) "\n" "")
1261 "\n\n")
1262 (if (and (stringp arglist)
1263 (string-match "\\`([^ ]+\\(.*\\))\\'" arglist))
1264 (concat "(fn" (match-string 1 arglist) ")")
1265 (format "%S" (help-make-usage 'fn arglist))))))
1266
1267(defun help-function-arglist (def &optional preserve-names)
1268 "Return a formal argument list for the function DEF.
1269IF PRESERVE-NAMES is non-nil, return a formal arglist that uses
1270the same names as used in the original source code, when possible."
1271 ;; Handle symbols aliased to other symbols.
1272 (if (and (symbolp def) (fboundp def)) (setq def (indirect-function def)))
1273 ;; If definition is a macro, find the function inside it.
1274 (if (eq (car-safe def) 'macro) (setq def (cdr def)))
1275 (cond
1276 ((and (byte-code-function-p def) (listp (aref def 0))) (aref def 0))
1277 ((eq (car-safe def) 'lambda) (nth 1 def))
1278 ((eq (car-safe def) 'closure) (nth 2 def))
1279 ((or (and (byte-code-function-p def) (integerp (aref def 0)))
1280 (subrp def))
1281 (or (when preserve-names
1282 (let* ((doc (condition-case nil (documentation def) (error nil)))
1283 (docargs (if doc (car (help-split-fundoc doc nil))))
1284 (arglist (if docargs
1285 (cdar (read-from-string (downcase docargs)))))
1286 (valid t))
1287 ;; Check validity.
1288 (dolist (arg arglist)
1289 (unless (and (symbolp arg)
1290 (let ((name (symbol-name arg)))
1291 (if (eq (aref name 0) ?&)
1292 (memq arg '(&rest &optional))
1293 (not (string-match "\\." name)))))
1294 (setq valid nil)))
1295 (when valid arglist)))
1296 (let* ((args-desc (if (not (subrp def))
1297 (aref def 0)
1298 (let ((a (subr-arity def)))
1299 (logior (car a)
1300 (if (numberp (cdr a))
1301 (lsh (cdr a) 8)
1302 (lsh 1 7))))))
1303 (max (lsh args-desc -8))
1304 (min (logand args-desc 127))
1305 (rest (logand args-desc 128))
1306 (arglist ()))
1307 (dotimes (i min)
1308 (push (intern (concat "arg" (number-to-string (1+ i)))) arglist))
1309 (when (> max min)
1310 (push '&optional arglist)
1311 (dotimes (i (- max min))
1312 (push (intern (concat "arg" (number-to-string (+ 1 i min))))
1313 arglist)))
1314 (unless (zerop rest) (push '&rest arglist) (push 'rest arglist))
1315 (nreverse arglist))))
1316 ((and (autoloadp def) (not (eq (nth 4 def) 'keymap)))
1317 "[Arg list not available until function definition is loaded.]")
1318 (t t)))
1319
1320(defun help-make-usage (function arglist)
1321 (cons (if (symbolp function) function 'anonymous)
1322 (mapcar (lambda (arg)
1323 (if (not (symbolp arg)) arg
1324 (let ((name (symbol-name arg)))
1325 (cond
1326 ((string-match "\\`&" name) arg)
1327 ((string-match "\\`_" name)
1328 (intern (upcase (substring name 1))))
1329 (t (intern (upcase name)))))))
1330 arglist)))
1331
1225 1332
1226(provide 'help) 1333(provide 'help)
1227 1334