Commit graph

139 commits

Author SHA1 Message Date
Mattias Engdegård
c21103bb76 Explicitly disallow named-let in code using dynamic binding
There is no point in permitting named-let to be used in dynbound code;
our code transforms are simply not valid in that context, and it's not
worth the trouble to make it work (to the extent that it is at all
possible). (Bug#59576)

* lisp/emacs-lisp/subr-x.el (named-let):
Error if used with dynamic binding.
* doc/lispref/variables.texi (Local Variables): Amend manual.
2023-08-21 14:17:03 +02:00
Eli Zaretskii
23f4999989 Merge from origin/emacs-29
0c29f53ab8 Fix 'string-pixel-width' under 'line-prefix'
7bbd7cae07 Fix find-dired-with-command for remote directories
c4a8572025 ; * etc/HISTORY: Fix Emacs 28.3 entry.
2023-08-04 03:17:49 -04:00
Eli Zaretskii
0c29f53ab8 Fix 'string-pixel-width' under 'line-prefix'
* lisp/emacs-lisp/subr-x.el (string-pixel-width): Disable
'line-prefix' and 'wrap-prefix' to avoid their effect on the
calculated string width.  (Bug#64971)
2023-07-31 21:50:45 +03:00
Sean Whitton
f16064f6bc Delete eval-command-interactive-spec
* etc/NEWS: Delete announcement of eval-command-interactive-spec.
* lisp/emacs-lisp/subr-x.el (eval-command-interactive-spec): Delete.
2023-06-21 13:26:09 +01:00
Sean Whitton
d751915ef4 eval-command-interactive-spec: Shorten code
* lisp/emacs-lisp/subr-x.el (eval-command-interactive-spec): Don't
reimplement checking for an 'interactive-form symbol property.
`interactive-form' already does this.  Thanks to Stefan Monnier.
2023-06-06 12:15:30 +01:00
Sean Whitton
a30781399b * subr-x (eval-command-interactive-spec): New function. 2023-06-04 20:16:55 +01:00
Mattias Engdegård
ef778f5143 Add more function declarations
* lisp/subr.el (buffer-narrowed-p, sha1, match-substitute-replacement)
(version-to-list, version<, version<=, version=)
(function-get, subregexp-context-p, split-string)
(combine-and-quote-strings, split-string-and-unquote)
(replace-regexp-in-string, syntax-after)
(string-trim-left, string-trim):
* lisp/emacs-lisp/subr-x.el (hash-table-empty-p, hash-table-keys)
(hash-table-values, string-glyph-split)
(string-clean-whitespace, string-fill, string-limit)
(string-pixel-width):
* lisp/env.el (substitute-env-vars, substitute-env-in-file-name)
(setenv-internal):
* lisp/emacs-lisp/rx.el (rx-to-string):
* lisp/emacs-lisp/regexp-opt.el (regexp-opt-depth)
(regexp-opt-charset):
Add appropriate declarations: pure, side-effect-free, and/or
important-return-value.
2023-05-26 13:57:02 +02:00
Mattias Engdegård
16ba96ad3d Add some pure and side-effect-free declarations
* lisp/subr.el (string-to-list, string-to-vector, string-or-null-p)
(booleanp, special-form-p, plistp, macrop, compiled-function-p)
(flatten-tree):
* lisp/emacs-lisp/subr-x.el (string-join, string-truncate-left)
(string-blank-p, string-remove-prefix, string-remove-suffix)
(string-pad, string-chop-newline):
Declare functions pure, side-effect-free, and/or error-free.
2023-02-15 12:04:13 +01:00
Eli Zaretskii
cae528457c ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
Stefan Kangas
9292f595a7 ; Fix typos 2022-12-31 12:43:32 +01:00
Eli Zaretskii
dad73e4de1 ; Review and fix NEWS and related documentation
* etc/NEWS: Fix wording, punctuation, and markup.

* lisp/emacs-lisp/subr-x.el (string-glyph-split): Doc fix.

* doc/lispref/display.texi (Displaying Messages): Document
'set-message-functions'.
2022-12-25 14:54:33 +02:00
Stefan Kangas
a15cd55044 ; Don't quote nil in comments 2022-12-15 02:35:00 +01:00
Eli Zaretskii
70a2eb4a0b Fix 'add-display-text-property' when OBJECT is non-nil
* lisp/emacs-lisp/subr-x.el (add-display-text-property): Fix the
case where OBJECT is not nil.  (Bug#59857)

* test/lisp/emacs-lisp/subr-x-tests.el
(subr-x-test-add-display-text-property): Add test for this case.
2022-12-06 14:41:36 +02:00
Juri Linkov
5c709bd605 Disable display-line-numbers-mode in string-pixel-width (bug#59311)
* lisp/emacs-lisp/subr-x.el (string-pixel-width):
Turn off display-line-numbers-mode when it's enabled.
2022-11-20 20:02:20 +02:00
Lars Ingebrigtsen
84801d468a Autoload string-join
* lisp/emacs-lisp/subr-x.el (string-join): Autoload since it's
being used more now.
2022-09-17 12:31:24 +02:00
Stefan Kangas
c4505fed53 Hide local variable section in emacs-news-modes
* lisp/textmodes/emacs-authors-mode.el
(emacs-authors-mode--hide-local-variables): Move from here...
* lisp/emacs-lisp/subr-x.el (emacs-etc--hide-local-variables):
...to here.

* lisp/textmodes/emacs-authors-mode.el (subr-x): Require.
(emacs-authors-mode): Use above renamed function.

* lisp/textmodes/emacs-news-mode.el (subr-x): Require.
(emacs-news--mode-common): Call 'emacs-etc--hide-local-variables'
to hide local variables section.
2022-08-12 22:28:17 +02:00
Mattias Engdegård
d8d582dc3c ; * lisp/emacs-lisp/subr-x.el (string-pad): Optimise. 2022-08-10 13:06:12 +02:00
Stefan Kangas
581fa3d958 Autoload string-blank-p
* lisp/eshell/em-hist.el (subr-x):
* lisp/net/eudc.el (subr-x): Don't require.
* lisp/emacs-lisp/subr-x.el (string-blank-p): Autoload.
2022-08-09 21:58:00 +02:00
Lars Ingebrigtsen
51f5c4b773 Fix off-by-one error in string-truncate-left
* lisp/emacs-lisp/subr-x.el (string-truncate-left): Fix off-by-one
error (bug#56685).
2022-07-23 08:58:53 +02:00
Lars Ingebrigtsen
bebf39f292 Autoload named-let
* lisp/emacs-lisp/subr-x.el (named-let): Autoload `named-let' for
easier use (bug#56473).
2022-07-11 12:18:04 +02:00
Eli Zaretskii
99872bedf0 ; * lisp/emacs-lisp/subr-x.el (string-limit): Clarify doc string. 2022-07-05 19:45:35 +03:00
Lars Ingebrigtsen
8681bf1e85 Mention byte order marks in string-limit doc string
* lisp/emacs-lisp/subr-x.el (string-limit): Mention byte order
marks (bug#48324).
2022-07-05 18:27:42 +02:00
Lars Ingebrigtsen
b72e4b1493 Make string-limit with encoding return complete glyphs
* lisp/emacs-lisp/subr-x.el (string-limit): Return more correct
results in the CODING-SYSTEM case for coding systems with BOM and
charset designations (bug#48324).  Also amend the algorithm to
return complete glyphs, not just complete code points.
2022-07-03 14:08:14 +02:00
Lars Ingebrigtsen
2f346b0ab1 Re-fix build warnings about subr-x defsubsts
* lisp/term/haiku-win.el (require):
* lisp/progmodes/elisp-mode.el (require):
* lisp/isearch.el (require): Require subr-x at compile time, since
these use defsubsts/macros from there.

* lisp/emacs-lisp/subr-x.el (string-empty-p): Move from here...
* lisp/simple.el (string-empty-p): ... to here.  This is to help
with a build problem where files.el is using the defsubst, but
requiring subr-x.el at compile time leads to load errors.
2022-06-25 12:20:05 +02:00
Lars Ingebrigtsen
49910adf87 Fix cl-generic bootstrap problems
* lisp/sqlite-mode.el (require):
* lisp/net/eudc.el (require):
* lisp/arc-mode.el (require): Require subr-x, since these files
are using macros from there.
* lisp/emacs-lisp/subr-x.el (with-memoization): Move from here...
* lisp/subr.el (with-memoization): ... to here, as it's used from
the preloaded cl-generic.el file.

* lisp/emacs-lisp/cl-generic.el (cl--generic-compiler): Don't use
the autoloaded `byte-compile' function during bootstrap.
(cl--generic-get-dispatcher): Don't require subr-x, either.

cl-generic has been preloaded since 2015, and most usages of it (in
preloaded files) work fine.  In particular, using `cl-defgeneric' is
unproblematic.  However, `cl-defmethod' would end up pulling in the
byte compiler (at load time), which would make it impossible to use
`cl-defmethod' in pre-loaded files, and this change fixes that (but
possibly not in the most self-evidently correct way).
2022-06-24 11:04:51 +02:00
Mattias Engdegård
4311bd0bd7 Slightly faster hash-table-keys and hash-table-values
* lisp/emacs-lisp/subr-x.el (hash-table-keys, hash-table-values):
Omit the reversal of the returned list.  It is not ordered anyway.
* test/lisp/emacs-lisp/subr-x-tests.el
(subr-x--hash-table-keys-and-values): New test.
2022-06-17 19:16:52 +02:00
Robert Pluim
eaa198cd75 ; Re-fix last change in doc of 'with-buffer-unmodified-if-unchanged'. 2022-05-04 14:53:34 +02:00
Eli Zaretskii
1a72248901 ; Fix last change in doc string of 'with-buffer-unmodified-if-unchanged'. 2022-05-04 13:08:53 +03:00
Eli Zaretskii
69521ffcb0 Clarify the doc string of 'with-buffer-unmodified-if-unchanged'
* lisp/emacs-lisp/subr-x.el (with-buffer-unmodified-if-unchanged):
Describe better what is meant by "buffer changes".  (Bug#4587)
2022-05-04 11:46:01 +03:00
Lars Ingebrigtsen
0a2f0e7f8c Make with-buffer-unmodified-if-unchanged more efficient
* lisp/emacs-lisp/subr-x.el (with-buffer-unmodified-if-unchanged):
Make more efficient.
2022-05-03 22:06:31 +02:00
Lars Ingebrigtsen
b7ddd0f2fd Make with-buffer-unmodified-if-unchanged more resilient
* lisp/emacs-lisp/subr-x.el (with-buffer-unmodified-if-unchanged):
Make more resilient.
2022-05-03 22:04:39 +02:00
Stefan Monnier
b5db5a6443 with-buffer-unmodified-if-unchanged: Tweak the implementation
* lisp/emacs-lisp/subr-x.el (with-buffer-unmodified-if-unchanged):
Skip the hash if the buffer was not modified at all.
Use `restore-buffer-modified-p`.
Also mention that it's imperative that the current buffer is preserved.
2022-05-03 15:35:47 -04:00
Lars Ingebrigtsen
59353ec7b5 Add new macro with-buffer-unmodified-if-unchanged
* lisp/emacs-lisp/subr-x.el (with-buffer-unmodified-if-unchanged):
New macro.
* lisp/textmodes/fill.el (fill-paragraph): Macro code copied from
here.  Adjust and use the macro.
2022-05-03 21:22:53 +02:00
Lars Ingebrigtsen
b05a103ea7 Move the when-let family of macros to subr.el
* lisp/subr.el (internal--build-binding)
(internal--build-bindings): Moved from subr-x.el and rewritten to
not use the threading macro.
(if-let*, when-let*, and-let*, if-let, when-let): Moved from
subr-x.el.  This avoids breaking the build every time somebody
uses these macros in functions that end up being called during
bootstrap.
2022-04-30 16:42:44 +02:00
Lars Ingebrigtsen
781c43de3d Fix bootstrap errors after previous easy-mmode change
* lisp/subr.el (ensure-empty-lines, string-lines): Moved from
subr-x so that they can be used in early bootstrap files.

* lisp/emacs-lisp/easy-mmode.el (easy-mmode--mode-docstring):
Don't use string-empty-p because of bootstrap issues.
2022-04-02 16:53:24 +02:00
Lars Ingebrigtsen
d710b84225 Make string-pixel-width about 40% faster
* lisp/emacs-lisp/subr-x.el (string-pixel-width): Speed up.
2022-02-20 16:14:05 +01:00
Lars Ingebrigtsen
babfb064c4 Make string-pixel-width slightly speedier
* lisp/emacs-lisp/subr-x.el (string-pixel-width): Speed up
string-pixel-width in the zero-length string case.
2022-02-19 14:21:19 +01:00
Phil Sainty
1c1d5eee4c Add new function to prompt a user for a process name
* lisp/emacs-lisp/subr-x.el (read-process-name): New function
(bug#32640).
2022-01-23 14:37:32 +01:00
Eli Zaretskii
dcd76bd48d Merge from origin/emacs-28
836be7a112 ; * etc/refcards/ru-refcard.tex: Update Copyright year.
86cbc6ee4a * lisp/net/tramp-sh.el: Adapt copyright year
ebe8772f65 ; Minor fixes related to copyright years
23c1ee6989 ; * test/manual/etags/ETAGS.good_N: Adjust to copyright ye...
8d3fc7ec89 * src/xfaces.c (face_for_font): Make 'hash' be uintptr_t.
19dcb237b5 ; Add 2022 to copyright years.

# Conflicts:
#	etc/NEWS
#	etc/refcards/ru-refcard.tex
#	lib/cdefs.h
#	lisp/erc/erc-dcc.el
#	lisp/erc/erc-imenu.el
#	lisp/erc/erc-replace.el
#	lisp/image-dired.el
#	lisp/progmodes/xref.el
#	m4/alloca.m4
#	m4/byteswap.m4
#	m4/errno_h.m4
#	m4/getopt.m4
#	m4/gnulib-common.m4
#	m4/inttypes.m4
#	m4/stddef_h.m4
#	m4/stdint.m4
#	m4/sys_socket_h.m4
2022-01-01 07:03:03 -05:00
Eli Zaretskii
19dcb237b5 ; Add 2022 to copyright years. 2022-01-01 02:45:51 -05:00
Lars Ingebrigtsen
e99bf27158 Remove APPEND argument from add-display-text-property
* doc/lispref/display.texi (Display Property): Update doc.
* lisp/emacs-lisp/subr-x.el (add-display-text-property): Remove
the append argument -- it's nonsensical.
2021-11-24 20:10:17 +01:00
Lars Ingebrigtsen
fde9363a57 Add new function 'add-display-text-property'
* doc/lispref/display.texi (Display Property): Document it.
* lisp/emacs-lisp/subr-x.el (add-display-text-property): New function.
2021-11-24 19:38:41 +01:00
Lars Ingebrigtsen
3a2eee6f74 Fix string-glyph-split infloop
* lisp/emacs-lisp/subr-x.el (string-glyph-split): Fix infloop when
applied to (string-glyph-split "✈️🌍") (bug#52067).
2021-11-24 08:27:22 +01:00
martin rudalics
61c254cafc Add new function buffer-text-pixel-size
* doc/lispref/display.texi (Size of Displayed Text): Document it.

* lisp/emacs-lisp/subr-x.el (string-pixel-width): Use
buffer-text-pixel-size (bug#51995).

* src/xdisp.c (window_text_pixel_size): Factor out from
Fwindow_text_pixel_size.
(Fbuffer_text_pixel_size): New function.
2021-11-22 12:02:42 +01:00
Robert Pluim
a491b73c76 Improve 'ensure-empty-lines' docstring
* lisp/emacs-lisp/subr-x.el (ensure-empty-lines): Fix typo and improve
wording.
2021-11-10 17:42:30 +01:00
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