1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-03 10:31:37 -08:00

Change the string-limit parameter semantics

* lisp/emacs-lisp/subr-x.el (string-limit): Alter the calling
convention.
This commit is contained in:
Lars Ingebrigtsen 2020-12-22 06:54:32 +01:00
parent d2b8611862
commit 9480169f1b
4 changed files with 22 additions and 19 deletions

View file

@ -286,17 +286,20 @@ result will have lines that are longer than LENGTH."
(fill-region (point-min) (point-max)))
(buffer-string)))
(defun string-limit (string length)
(defun string-limit (string length &optional end)
"Return (up to) a LENGTH substring of STRING.
If STRING is shorter than or equal to LENGTH, the entire string
is returned unchanged. If STRING is longer than LENGTH, and
LENGTH is a positive number, return a substring consisting of the
first LENGTH characters of STRING. If LENGTH is negative, return
a substring consisting of the last LENGTH characters of STRING."
is returned unchanged.
If STRING is longer than LENGTH, return a substring consisting of
the first LENGTH characters of STRING. If END is non-nil, return
the last LENTGH characters instead."
(unless (natnump length)
(signal 'wrong-type-argument (list 'natnump length)))
(cond
((<= (length string) (abs length)) string)
((>= length 0) (substring string 0 length))
((substring string length))))
((<= (length string) length) string)
(end (substring string (- (length string) length)))
(t (substring string 0 length))))
(defun string-lines (string &optional omit-nulls)
"Split STRING into a list of lines.