comparison lisp/subr.el @ 55406:3b27c2f86c7a

(lambda): Add arglist description to docstring. (declare): Fix typo in docstring. (open-network-stream): Fix docstring. (process-kill-without-query): Fix docstring and add obsolescence info. (last, butlast, nbutlast): Make arguments match their use in docstring. (insert-buffer-substring-no-properties): Likewise. (insert-buffer-substring-as-yank): Likewise. (split-string): Fix docstring.
author Juanma Barranquero <lekktu@gmail.com>
date Fri, 07 May 2004 01:06:20 +0000
parents 32822ce3259d
children e191e6d1554e
comparison
equal deleted inserted replaced
55405:79eecb3f0e5a 55406:3b27c2f86c7a
88 DOCSTRING is an optional documentation string. 88 DOCSTRING is an optional documentation string.
89 If present, it should describe how to call the function. 89 If present, it should describe how to call the function.
90 But documentation strings are usually not useful in nameless functions. 90 But documentation strings are usually not useful in nameless functions.
91 INTERACTIVE should be a call to the function `interactive', which see. 91 INTERACTIVE should be a call to the function `interactive', which see.
92 It may also be omitted. 92 It may also be omitted.
93 BODY should be a list of Lisp expressions." 93 BODY should be a list of Lisp expressions.
94
95 \(fn ARGS [DOCSTRING] [INTERACTIVE] BODY)"
94 ;; Note that this definition should not use backquotes; subr.el should not 96 ;; Note that this definition should not use backquotes; subr.el should not
95 ;; depend on backquote.el. 97 ;; depend on backquote.el.
96 (list 'function (cons 'lambda cdr))) 98 (list 'function (cons 'lambda cdr)))
97 99
98 (defmacro push (newelt listname) 100 (defmacro push (newelt listname)
159 ,@(cdr (cdr spec))))) 161 ,@(cdr (cdr spec)))))
160 162
161 (defmacro declare (&rest specs) 163 (defmacro declare (&rest specs)
162 "Do not evaluate any arguments and return nil. 164 "Do not evaluate any arguments and return nil.
163 Treated as a declaration when used at the right place in a 165 Treated as a declaration when used at the right place in a
164 `defmacro' form. \(See Info anchor `(elisp)Definition of declare'." 166 `defmacro' form. \(See Info anchor `(elisp)Definition of declare'.)"
165 nil) 167 nil)
166 168
167 (defsubst caar (x) 169 (defsubst caar (x)
168 "Return the car of the car of X." 170 "Return the car of the car of X."
169 (car (car x))) 171 (car (car x)))
178 180
179 (defsubst cddr (x) 181 (defsubst cddr (x)
180 "Return the cdr of the cdr of X." 182 "Return the cdr of the cdr of X."
181 (cdr (cdr x))) 183 (cdr (cdr x)))
182 184
183 (defun last (x &optional n) 185 (defun last (list &optional n)
184 "Return the last link of the list X. Its car is the last element. 186 "Return the last link of LIST. Its car is the last element.
185 If X is nil, return nil. 187 If LIST is nil, return nil.
186 If N is non-nil, return the Nth-to-last link of X. 188 If N is non-nil, return the Nth-to-last link of LIST.
187 If N is bigger than the length of X, return X." 189 If N is bigger than the length of LIST, return LIST."
188 (if n 190 (if n
189 (let ((m 0) (p x)) 191 (let ((m 0) (p list))
190 (while (consp p) 192 (while (consp p)
191 (setq m (1+ m) p (cdr p))) 193 (setq m (1+ m) p (cdr p)))
192 (if (<= n 0) p 194 (if (<= n 0) p
193 (if (< n m) (nthcdr (- m n) x) x))) 195 (if (< n m) (nthcdr (- m n) list) list)))
194 (while (consp (cdr x)) 196 (while (consp (cdr list))
195 (setq x (cdr x))) 197 (setq list (cdr list)))
196 x)) 198 list))
197 199
198 (defun butlast (x &optional n) 200 (defun butlast (list &optional n)
199 "Returns a copy of LIST with the last N elements removed." 201 "Returns a copy of LIST with the last N elements removed."
200 (if (and n (<= n 0)) x 202 (if (and n (<= n 0)) list
201 (nbutlast (copy-sequence x) n))) 203 (nbutlast (copy-sequence list) n)))
202 204
203 (defun nbutlast (x &optional n) 205 (defun nbutlast (list &optional n)
204 "Modifies LIST to remove the last N elements." 206 "Modifies LIST to remove the last N elements."
205 (let ((m (length x))) 207 (let ((m (length list)))
206 (or n (setq n 1)) 208 (or n (setq n 1))
207 (and (< n m) 209 (and (< n m)
208 (progn 210 (progn
209 (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil)) 211 (if (> n 0) (setcdr (nthcdr (- (1- m) n) list) nil))
210 x)))) 212 list))))
211 213
212 (defun delete-dups (list) 214 (defun delete-dups (list)
213 "Destructively remove `equal' duplicates from LIST. 215 "Destructively remove `equal' duplicates from LIST.
214 Store the result in LIST and return it. LIST must be a proper list. 216 Store the result in LIST and return it. LIST must be a proper list.
215 Of several `equal' occurrences of an element in LIST, the first 217 Of several `equal' occurrences of an element in LIST, the first
1112 1114
1113 (defun open-network-stream (name buffer host service) 1115 (defun open-network-stream (name buffer host service)
1114 "Open a TCP connection for a service to a host. 1116 "Open a TCP connection for a service to a host.
1115 Returns a subprocess-object to represent the connection. 1117 Returns a subprocess-object to represent the connection.
1116 Input and output work as for subprocesses; `delete-process' closes it. 1118 Input and output work as for subprocesses; `delete-process' closes it.
1119
1117 Args are NAME BUFFER HOST SERVICE. 1120 Args are NAME BUFFER HOST SERVICE.
1118 NAME is name for process. It is modified if necessary to make it unique. 1121 NAME is name for process. It is modified if necessary to make it unique.
1119 BUFFER is the buffer (or buffer-name) to associate with the process. 1122 BUFFER is the buffer (or buffer-name) to associate with the process.
1120 Process output goes at end of that buffer, unless you specify 1123 Process output goes at end of that buffer, unless you specify
1121 an output stream or filter function to handle the output. 1124 an output stream or filter function to handle the output.
1176 )) ;; (featurep 'make-network-process) 1179 )) ;; (featurep 'make-network-process)
1177 1180
1178 1181
1179 ;; compatibility 1182 ;; compatibility
1180 1183
1184 (make-obsolete 'process-kill-without-query
1185 "use `process-query-on-exit-flag'\nor `set-process-query-on-exit-flag'."
1186 "21.5")
1181 (defun process-kill-without-query (process &optional flag) 1187 (defun process-kill-without-query (process &optional flag)
1182 "Say no query needed if PROCESS is running when Emacs is exited. 1188 "Say no query needed if PROCESS is running when Emacs is exited.
1183 Optional second argument if non-nil says to require a query. 1189 Optional second argument if non-nil says to require a query.
1184 Value is t if a query was formerly required. 1190 Value is t if a query was formerly required."
1185 New code should not use this function; use `process-query-on-exit-flag'
1186 or `set-process-query-on-exit-flag' instead."
1187 (let ((old (process-query-on-exit-flag process))) 1191 (let ((old (process-query-on-exit-flag process)))
1188 (set-process-query-on-exit-flag process nil) 1192 (set-process-query-on-exit-flag process nil)
1189 old)) 1193 old))
1190 1194
1191 ;; process plist management 1195 ;; process plist management
1691 (if (eq yank-undo-function t) ;; not set by FUNCTION 1695 (if (eq yank-undo-function t) ;; not set by FUNCTION
1692 (setq yank-undo-function (nth 3 handler))) ;; UNDO 1696 (setq yank-undo-function (nth 3 handler))) ;; UNDO
1693 (if (nth 4 handler) ;; COMMAND 1697 (if (nth 4 handler) ;; COMMAND
1694 (setq this-command (nth 4 handler))))) 1698 (setq this-command (nth 4 handler)))))
1695 1699
1696 (defun insert-buffer-substring-no-properties (buf &optional start end) 1700 (defun insert-buffer-substring-no-properties (buffer &optional start end)
1697 "Insert before point a substring of buffer BUFFER, without text properties. 1701 "Insert before point a substring of BUFFER, without text properties.
1698 BUFFER may be a buffer or a buffer name. 1702 BUFFER may be a buffer or a buffer name.
1699 Arguments START and END are character numbers specifying the substring. 1703 Arguments START and END are character numbers specifying the substring.
1700 They default to the beginning and the end of BUFFER." 1704 They default to the beginning and the end of BUFFER."
1701 (let ((opoint (point))) 1705 (let ((opoint (point)))
1702 (insert-buffer-substring buf start end) 1706 (insert-buffer-substring buffer start end)
1703 (let ((inhibit-read-only t)) 1707 (let ((inhibit-read-only t))
1704 (set-text-properties opoint (point) nil)))) 1708 (set-text-properties opoint (point) nil))))
1705 1709
1706 (defun insert-buffer-substring-as-yank (buf &optional start end) 1710 (defun insert-buffer-substring-as-yank (buffer &optional start end)
1707 "Insert before point a part of buffer BUFFER, stripping some text properties. 1711 "Insert before point a part of BUFFER, stripping some text properties.
1708 BUFFER may be a buffer or a buffer name. Arguments START and END are 1712 BUFFER may be a buffer or a buffer name.
1709 character numbers specifying the substring. They default to the 1713 Arguments START and END are character numbers specifying the substring.
1710 beginning and the end of BUFFER. Strip text properties from the 1714 They default to the beginning and the end of BUFFER.
1711 inserted text according to `yank-excluded-properties'." 1715 Strip text properties from the inserted text according to
1716 `yank-excluded-properties'."
1712 ;; Since the buffer text should not normally have yank-handler properties, 1717 ;; Since the buffer text should not normally have yank-handler properties,
1713 ;; there is no need to handle them here. 1718 ;; there is no need to handle them here.
1714 (let ((opoint (point))) 1719 (let ((opoint (point)))
1715 (insert-buffer-substring buf start end) 1720 (insert-buffer-substring buffer start end)
1716 (remove-yank-excluded-properties opoint (point)))) 1721 (remove-yank-excluded-properties opoint (point))))
1717 1722
1718 1723
1719 ;; Synchronous shell commands. 1724 ;; Synchronous shell commands.
1720 1725
2071 If SEPARATORS is non-nil, it should be a regular expression matching text 2076 If SEPARATORS is non-nil, it should be a regular expression matching text
2072 which separates, but is not part of, the substrings. If nil it defaults to 2077 which separates, but is not part of, the substrings. If nil it defaults to
2073 `split-string-default-separators', normally \"[ \\f\\t\\n\\r\\v]+\", and 2078 `split-string-default-separators', normally \"[ \\f\\t\\n\\r\\v]+\", and
2074 OMIT-NULLS is forced to t. 2079 OMIT-NULLS is forced to t.
2075 2080
2076 If OMIT-NULLs is t, zero-length substrings are omitted from the list \(so 2081 If OMIT-NULLS is t, zero-length substrings are omitted from the list \(so
2077 that for the default value of SEPARATORS leading and trailing whitespace 2082 that for the default value of SEPARATORS leading and trailing whitespace
2078 are effectively trimmed). If nil, all zero-length substrings are retained, 2083 are effectively trimmed). If nil, all zero-length substrings are retained,
2079 which correctly parses CSV format, for example. 2084 which correctly parses CSV format, for example.
2080 2085
2081 Note that the effect of `(split-string STRING)' is the same as 2086 Note that the effect of `(split-string STRING)' is the same as