Commit graph

94 commits

Author SHA1 Message Date
Lars Ingebrigtsen
c23cb2861e Add new function string-glyph-split
* doc/lispref/strings.texi (Creating Strings): Document it.
* lisp/emacs-lisp/shortdoc.el (string): Mention it.

* lisp/emacs-lisp/subr-x.el (string-glyph-split): New function.
2021-10-30 15:22:36 +02:00
Eli Zaretskii
c30f95078c Merge from origin/emacs-28
20ebd91a73 Improve documentation of string truncation APIs
3f998a3fc8 * lisp/textmodes/css-mode.el: Fix typo.  (Bug#51488)
2021-10-30 04:07:09 -04:00
Eli Zaretskii
20ebd91a73 Improve documentation of string truncation APIs
* doc/lispref/display.texi (Size of Displayed Text):
* lisp/international/mule-util.el (truncate-string-to-width):
Document caveats of using 'truncate-string-to-width' when
character composition is involved.

* lisp/emacs-lisp/subr-x.el (string-limit):
* doc/lispref/strings.texi (Creating Strings): Improve the
documentation of 'string-limit'.
2021-10-30 10:26:38 +03:00
Stefan Monnier
c22b735f0c (string-pixel-width): Rewrite to avoid side effects
* src/xdisp.c (Fwindow_text_pixel_size): Allow `window` to be a buffer.
* lisp/emacs-lisp/subr-x.el (string-pixel-width): Simplify accordingly.
2021-10-27 14:03:43 -04:00
Lars Ingebrigtsen
7c6f7dc99b Simplify string-pixel-width
* lisp/emacs-lisp/subr-x.el (string-pixel-width): Simplify --
save-window-excursion saves dedication status (and the code was
buggy).
2021-10-27 16:50:40 +02:00
Lars Ingebrigtsen
03366de394 Add new function 'string-pixel-width'
* doc/lispref/display.texi (Size of Displayed Text): Mention it.
* lisp/emacs-lisp/shortdoc.el (string): Mention it.

* lisp/emacs-lisp/subr-x.el (string-pixel-width): New function.
2021-10-27 15:41:32 +02:00
Stefan Kangas
d652efcd08 Make 'mapconcat' argument 'separator' optional
* src/fns.c (Fmapconcat): Make third 'separator' argument
optional.  (Bug#50965)
* doc/lispref/functions.texi (Mapping Functions): Update
documentation for above change.
* test/src/fns-tests.el (fns-tests-mapconcat): New test.

* doc/misc/cl.texi (Obsolete Setf Customization): Don't use third
mapconcat argument in example.
* lisp/emacs-lisp/subr-x.el (string-join): Doc fix.
2021-10-05 15:38:38 +02:00
Lars Ingebrigtsen
8b4a6a722a Add new command 'ensure-empty-lines'.
* doc/lispref/text.texi (Commands for Insertion): Document it.

* lisp/emacs-lisp/subr-x.el (ensure-empty-lines): New command.
2021-10-04 13:23:22 +02:00
Stefan Monnier
3c972723e4 * lisp/emacs-lisp/subr-x.el (with-memoization): New macro
Extracted from `cl-generic.el`.

* lisp/emacs-lisp/cl-generic.el (cl--generic-get-dispatcher)
(cl--generic-build-combined-method, cl-generic-generalizers): Use it.
(cl--generic-with-memoization): Delete.
2021-10-01 14:33:37 -04:00
Lars Ingebrigtsen
2a73673809 Change how thread-first/thread-last indent the first argument
* lisp/doc-view.el (doc-view--current-cache-dir): Reindent.

* lisp/emacs-lisp/subr-x.el (thread-first):
(thread-last): Change indentation to match examples.
(internal--build-binding): Reindent.

* test/lisp/emacs-lisp/subr-x-tests.el
(subr-x-test-thread-first-function-names-are-threaded):
(subr-x-test-thread-first-examples):
(subr-x-test-thread-last-function-names-are-threaded):
(subr-x-test-thread-last-examples): Reindent.
2021-09-22 05:57:48 +02:00
Lars Ingebrigtsen
e91b574bf8 Add new functions for lax mail address splitting
* lisp/emacs-lisp/subr-x.el (string-clean-whitespace): Autoload.
* lisp/mail/mail-parse.el (mail-header-parse-addresses-lax)
(mail-header-parse-address-lax): New functions.
2021-08-14 15:20:59 +02:00
Lars Ingebrigtsen
b188861af4 Attempt to make defclass documentation more legible
* lisp/emacs-lisp/cl-extra.el (cl--print-table): Attempt to make
defclass documentation more readable (bug#30998).
(cl--describe-class-slots): Ditto.
2021-06-24 20:24:43 +02:00
Stefan Monnier
84e207c811 * lisp/emacs-lisp/subr-x.el (if-let*, if-let): Use looser Edebug spec
This makes the same spec work both for `if-let` and `when-let`.

(when-let*, and-let*, when-let): Simplify accordingly.
2021-05-22 10:21:59 -04:00
Philipp Stephani
33a52cb458 Give 'when-let' and 'when-let*' their own Edebug specification.
The Edebug specification of 'if-let' and 'if-let*' doesn't work if the
body is empty.  While that's a pathological case, it's not wrong per
se, and could arguably happen due to macro expansion.

* lisp/emacs-lisp/subr-x.el (when-let*, when-let): Don't reuse Edebug
specification from 'if-let*' and 'if-let'.
2021-05-22 13:29:50 +02:00
Philipp Stephani
9676d41b83 * lisp/emacs-lisp/subr-x.el (if-let): Swap &or branches (Bug#48489) 2021-05-18 09:26:49 +02:00
Eli Zaretskii
98e5639c3c Fix the tests for 'string-limit'
* test/lisp/emacs-lisp/subr-x-tests.el (subr-string-limit-coding):
Fix the expected results of string-limit when encoding with
UTF-16.  Add tests for UTF-8 with BOM.  (Bug#48324)

* lisp/emacs-lisp/subr-x.el (string-limit): Add FIXME comment
about the current implementation, which is faulty by design.
2021-05-12 16:41:03 +03:00
Lars Ingebrigtsen
a4ececf004 Move string-trim functions to subr.el
* doc/lispref/strings.texi (Creating Strings): Document them.

* lisp/faces.el: Don't require subr-x, because that leads to build
errors.

* lisp/subr.el (string-trim, string-trim-right)
(string-trim-left): Move here from subr-x.el.

* lisp/emacs-lisp/shortdoc.el (string): Adjust.
2021-03-24 09:22:44 +01:00
Stefan Monnier
0d3635536d * lisp/emacs-lisp/subr-x.el (named-let): New macro 2021-01-20 14:13:15 -05:00
Paul Eggert
ba05d005e5 Update copyright year to 2021
Run "TZ=UTC0 admin/update-copyright".
2021-01-01 01:13:56 -08:00
Lars Ingebrigtsen
af359de917 Allow `string-limit' to work on encoded strings
* doc/lispref/strings.texi (Creating Strings): Document it.

* lisp/emacs-lisp/subr-x.el (string-limit): Allow limiting on
encoded strings.
2020-12-25 05:58:09 +01:00
Lars Ingebrigtsen
269cec13a2 Remove `string-slice' -- it's not very well defined
* doc/lispref/strings.texi (Creating Strings): Ditto.

* lisp/emacs-lisp/subr-x.el (string-slice): Remove.
2020-12-25 05:16:46 +01:00
Lars Ingebrigtsen
5c86a53296 Improve the string-limit doc string
* lisp/emacs-lisp/subr-x.el (string-limit): Mention
truncate-string-to-width in the doc string.
2020-12-23 07:59:24 +01:00
Lars Ingebrigtsen
22c1f00d99 Allow string-slice to take zero-length matches
* lisp/emacs-lisp/subr-x.el (string-slice): Allow zero-length
matches.  Code adapted from s.el by Magnar Sveen.
2020-12-23 07:45:19 +01:00
Basil L. Contovounesios
e42a63a960 ; Fix docstrings in last change to subr-x.el 2020-12-22 09:01:47 +00:00
Lars Ingebrigtsen
051d8f7535 Make string-pad take an optional START parameter
* lisp/emacs-lisp/subr-x.el (string-pad): Alter the calling
convention.
2020-12-22 06:59:25 +01:00
Lars Ingebrigtsen
9480169f1b Change the string-limit parameter semantics
* lisp/emacs-lisp/subr-x.el (string-limit): Alter the calling
convention.
2020-12-22 06:54:32 +01:00
Lars Ingebrigtsen
d2b8611862 Further string-clean-whitespace tweaks
* lisp/emacs-lisp/subr-x.el (string-clean-whitespace): Put \r
back, which was mistakenly removed.
2020-12-22 04:24:25 +01:00
Basil L. Contovounesios
27fab4b140 Tiny string-clean-whitespace simplification
* lisp/emacs-lisp/subr-x.el (string-clean-whitespace): Streamline by
treating replacement string as being literal and having fixed case.
2020-12-21 22:36:55 +00:00
Lars Ingebrigtsen
7e86d3bb9b Make string-chop-newline more efficient
* lisp/emacs-lisp/subr-x.el (string-chop-newline): Make more
efficient.
2020-12-21 23:18:05 +01:00
Lars Ingebrigtsen
768522750d Make string-clean-whitespace work on non-ASCII whitespace, too
* lisp/emacs-lisp/subr-x.el (string-clean-whitespace): Also clean
up non-ASCII whitespace.
2020-12-21 22:41:37 +01:00
Lars Ingebrigtsen
f329a3180e Add string-chop-newline
* doc/lispref/strings.texi (Creating Strings): Document it.
* lisp/emacs-lisp/subr-x.el (string-chop-newline): Add new function.
2020-12-21 22:05:37 +01:00
Basil L. Contovounesios
e967ba3018 ; Fix recent string utility additions
* etc/NEWS: Fix typo.
* lisp/emacs-lisp/subr-x.el (string-limit): Fix typos in docstring.
Simplify.
(string-slice): Improve docstring wording.
(string-pad): Simplify.
2020-12-21 20:51:29 +00:00
Lars Ingebrigtsen
fd9431dde4 Fix shorter-than-length case for string-limit
* lisp/emacs-lisp/subr-x.el (string-limit): Fix
shorter-than-length case.
2020-12-21 20:42:17 +01:00
Lars Ingebrigtsen
cf2e832185 Rename slice-string to string-slice
* lisp/emacs-lisp/subr-x.el (string-slice): Rename from slice-string.
* doc/lispref/strings.texi (Creating Strings): Ditto.
2020-12-21 20:18:57 +01:00
Lars Ingebrigtsen
b3dec31766 Add `string-pad'
* doc/lispref/strings.texi (Creating Strings): Document it.
* lisp/emacs-lisp/shortdoc.el (string): Add example.

* lisp/emacs-lisp/subr-x.el (string-pad): New function.
2020-12-21 20:01:28 +01:00
Lars Ingebrigtsen
87e422f104 Beef up the Emacs string utility set a bit
* doc/lispref/strings.texi (Modifying Strings): Document them.
* lisp/emacs-lisp/shortdoc.el (string): Add examples.

* lisp/emacs-lisp/subr-x.el (string-clean-whitespace)
(string-fill, string-limit, string-lines, slice-string): New
functions.
2020-12-21 18:53:40 +01:00
Lars Ingebrigtsen
e608477da2 Give better error feedback on wrong password in .gpg files
* lisp/epa-file.el (epa-file--find-file-not-found-function): Do a
user-error when there's a wrong password (bug#43704).
(epa--wrong-password-p): New function.
(epa-file-insert-file-contents): Use it, and stash the error away
for later signalling.

* lisp/emacs-lisp/subr-x.el (if-let): Autoload.
2020-09-30 03:47:47 +02:00
Štěpán Němec
188bd80a90 gnus-shorten-url: Improve and avoid args-out-of-range error
'gnus-shorten-url' (used by 'gnus-summary-browse-url') ignored
fragment identifiers and didn't check substring bounds, in some cases
leading to runtime errors, e.g.:

  (gnus-shorten-url "https://some.url.with/path/and#also_a_long_target" 40)
  ;; => Lisp error: (args-out-of-range "/path/and" -18 nil)

This commit makes it account for #fragments and fixes faulty string
computation, reusing existing helper function.  (bug#39980)

* lisp/vc/ediff-init.el (ediff-truncate-string-left): Rename to
'string-truncate-left' and move...
* lisp/emacs-lisp/subr-x.el (string-truncate-left):  ...here.
All callers changed.
* lisp/gnus/gnus-sum.el (gnus-shorten-url): Fix args-out-of-range
error, don't drop #fragments, use 'string-truncate-left'.
2020-04-13 12:12:00 +02:00
Paul Eggert
365e01cc9f Update copyright year to 2020
Run "TZ=UTC0 admin/update-copyright $(git ls-files)".
2020-01-01 00:59:52 +00:00
Lars Ingebrigtsen
c56fabdfc7 Move describe-face to the new help-fns machinery
* lisp/help-fns.el (describe-face): Move to here from faces.el and
split up (bug#36670).
(help-fns--face-custom-version-info):
(help-fns--face-attributes): Factored out into own functions.
(help-fns-describe-face-functions): New variable.

* lisp/emacs-lisp/subr-x.el (when-let): Add autoload cookie.
2019-09-21 00:45:41 +02:00
Mattias Engdegård
4051fa3ba9 Clarify what counts as whitespace in `string-blank-p'
* lisp/emacs-lisp/subr-x.el (string-blank-p): Expand doc string.
2019-09-01 14:28:01 +02:00
Alex Branham
0b7494414a (if-let): Improve docstring by mentioning let*
* lisp/emacs-lisp/subr-x.el (if-let): Clarify that if-let is like
let*, not like let (bug#33550).
2019-06-23 22:55:40 +02:00
Paul Eggert
f744797af1 Go back to "Maintainer: emacs-devel@gnu.org"
Restore lines saying "Maintainer: emacs-devel@gnu.org" when there is
no special maintainer for a file.  Although this wasn't documented
it was common practice and removing the lines didn't have consensus.
2019-05-25 14:25:18 -07:00
Paul Eggert
bef1be8730 Fixes for "Maintainer:" and related lines
Mostly, this just removes "Maintainer: emacs-devel@gnu.org" lines,
which are not that useful.  It also cleans up and regularizes a
few similar lines.
2019-05-19 21:34:27 -07:00
Tassilo Horn
e96923c188 Improve replace-buffer-contents/replace-region-contents
* src/editfns.c (Freplace_buffer_contents): Add two optional arguments
  for mitigating performance issues.
* lisp/emacs-lisp/subr-x.el (replace-region-contents): Move from
  subr.el.  Add the same two arguments as for replace-buffer-contents.
* lisp/json.el (json-pretty-print-max-secs): New variable holding the
  default MAX-SECS value json-pretty-print passes to
  replace-buffer-contents.
  (json-pretty-print): Use it.
* doc/lispref/text.texi (Replacing): Add documentation for
  replace-buffer-contents two new optional arguments.  Document
  replace-region-contents.
2019-02-23 21:31:15 +01:00
Paul Eggert
ba809612c0 Merge from origin/emacs-26
2fcf2df Fix copyright years by hand
26bed8b Update copyright year to 2019
2814292 Fix value of default frame height.  (Bug#33921)
2018-12-31 17:57:29 -08:00
Paul Eggert
26bed8ba10 Update copyright year to 2019
Run 'TZ=UTC0 admin/update-copyright $(git ls-files)'.
2019-01-01 01:01:13 +00:00
Glenn Morris
e5634aae53 Merge from origin/emacs-26
745c9c0 (origin/emacs-26) Revert "Revert "Fix infloop in GC mark_kboa...
c418c85 Revert "Fix infloop in GC mark_kboards"
8fa0d96 * lisp/emacs-lisp/subr-x.el (if-let, when-let): Doc fix: acti...
2018-12-02 10:32:25 -08:00
Glenn Morris
8fa0d9679d * lisp/emacs-lisp/subr-x.el (if-let, when-let): Doc fix: active voice. 2018-12-01 17:21:29 -08:00
Basil L. Contovounesios
1013e0392b Tweak subr-x.el substring functions
* lisp/emacs-lisp/subr-x.el (string-join): #'-quote function symbol.
(string-trim-left, string-trim-right):
Make better use of substring for minor speedup.
* test/lisp/emacs-lisp/subr-x-tests.el
(subr-x-test-string-trim-left, subr-x-test-string-trim-right)
(subr-x-test-string-remove-prefix)
(subr-x-test-string-remove-suffix): New tests.
2018-07-13 11:28:16 -04:00