From 2db8b0e12f913ecd720aa81a70580e58fd032397 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Sat, 3 Sep 2022 18:47:04 +0200 Subject: Add new function `seq-remove-at-position' * doc/lispref/sequences.texi (Sequence Functions): Document it. * lisp/emacs-lisp/seq.el (seq-remove-at-position): New function. * lisp/emacs-lisp/shortdoc.el (sequence): Mention it. * test/lisp/emacs-lisp/seq-tests.el (test-seq-remove-at-position): Test it. --- lisp/emacs-lisp/shortdoc.el | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lisp/emacs-lisp/shortdoc.el') diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index 990dabe351a..6a366ec0fc0 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -888,6 +888,9 @@ A FUNC form can have any number of `:no-eval' (or `:no-value'), :eval (seq-filter #'numberp '(a b 3 4 f 6))) (seq-remove :eval (seq-remove #'numberp '(1 2 c d 5))) + (seq-remove-at-position + :eval (seq-remove-at-position '(a b c d e) 3) + :eval (seq-remove-at-position [a b c d e] 0)) (seq-group-by :eval (seq-group-by #'cl-plusp '(-1 2 3 -4 -5 6))) (seq-union -- cgit v1.2.3 From 4751b51d5e1182975aa002af08a625e4859ec276 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Sun, 4 Sep 2022 13:21:59 +0200 Subject: Add new function `seq-positions' * doc/lispref/sequences.texi (Sequence Functions): Document it. * lisp/emacs-lisp/seq.el (seq-positions): New function. * lisp/emacs-lisp/shortdoc.el (sequence): Mention it. * test/lisp/emacs-lisp/seq-tests.el (test-seq-positions): Test it (bug#57548). --- doc/lispref/sequences.texi | 21 +++++++++++++++++++++ etc/NEWS | 5 +++++ lisp/emacs-lisp/seq.el | 17 +++++++++++++++++ lisp/emacs-lisp/shortdoc.el | 4 ++++ test/lisp/emacs-lisp/seq-tests.el | 7 +++++++ 5 files changed, 54 insertions(+) (limited to 'lisp/emacs-lisp/shortdoc.el') diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index 2ee19efb1a9..214b1e76e15 100644 --- a/doc/lispref/sequences.texi +++ b/doc/lispref/sequences.texi @@ -898,6 +898,27 @@ use instead of the default @code{equal}. @end example @end defun +@defun seq-positions sequence elt &optional testfn + This function returns a list of the (zero-based) indices of the +elements in @var{sequence} for which @var{testfn} returns +non-@code{nil} when passed the element and @var{elt} as +arguments. @var{testfn} defaults to @code{equal}. + +@example +@group +(seq-positions '(a b c a d) 'a) +@result{} (0 3) +@end group +@group +(seq-positions '(a b c a d) 'z) +@result{} nil +@end group +@group +(seq-positions '(11 5 7 12 9 15) 10 #'>=) +@result{} (0 3 5) +@end group +@end example +@end defun @defun seq-uniq sequence &optional function This function returns a list of the elements of @var{sequence} with diff --git a/etc/NEWS b/etc/NEWS index ee450317a0c..6c0cf19fe6b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2742,6 +2742,11 @@ compiler now emits a warning about this deprecated usage. These can be used for buttons in buffers and the like. See the "(elisp) Icons" and "(emacs) Icons" nodes in the manuals for details. ++++ +** New function 'seq-positions'. +This returns a list of the (zero-based) indices of elements matching a +given predicate in the specified sequence. + +++ ** New arguments MESSAGE and TIMEOUT of 'set-transient-map'. MESSAGE specifies a message to display after activating the transient diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index 64197b55e5f..31dcfa98b40 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -459,6 +459,23 @@ Equality is defined by the function TESTFN, which defaults to `equal'." (setq index (1+ index))) nil))) +;;;###autoload +(cl-defgeneric seq-positions (sequence elt &optional testfn) + "Return indices for which (TESTFN (seq-elt SEQUENCE index) ELT) is non-nil. + +TESTFN is a two-argument function which is passed each element of +SEQUENCE as first argument and ELT as second. TESTFN defaults to +`equal'. + +The result is a list of (zero-based) indices." + (let ((result '())) + (seq-do-indexed + (lambda (e index) + (when (funcall (or testfn #'equal) e elt) + (push index result))) + sequence) + (nreverse result))) + ;;;###autoload (cl-defgeneric seq-uniq (sequence &optional testfn) "Return a list of the elements of SEQUENCE with duplicates removed. diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index 6a366ec0fc0..2472479bad6 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -846,6 +846,10 @@ A FUNC form can have any number of `:no-eval' (or `:no-value'), :eval (seq-find #'numberp '(a b 3 4 f 6))) (seq-position :eval (seq-position '(a b c) 'c)) + (seq-positions + :eval (seq-positions '(a b c a d) 'a) + :eval (seq-positions '(a b c a d) 'z) + :eval (seq-positions '(11 5 7 12 9 15) 10 #'>=)) (seq-length :eval (seq-length "abcde")) (seq-max diff --git a/test/lisp/emacs-lisp/seq-tests.el b/test/lisp/emacs-lisp/seq-tests.el index 6249e486173..d95b35c45eb 100644 --- a/test/lisp/emacs-lisp/seq-tests.el +++ b/test/lisp/emacs-lisp/seq-tests.el @@ -490,6 +490,13 @@ Evaluate BODY for each created sequence. (should (= (seq-position seq 'a #'eq) 0)) (should (null (seq-position seq (make-symbol "a") #'eq))))) +(ert-deftest test-seq-positions () + (with-test-sequences (seq '(1 2 3 1 4)) + (should (equal '(0 3) (seq-positions seq 1))) + (should (seq-empty-p (seq-positions seq 9)))) + (with-test-sequences (seq '(11 5 7 12 9 15)) + (should (equal '(0 3 5) (seq-positions seq 10 #'>=))))) + (ert-deftest test-seq-sort-by () (let ((seq ["x" "xx" "xxx"])) (should (equal (seq-sort-by #'seq-length #'> seq) -- cgit v1.2.3 From 8a224e5124f4a64054d570054a37d2e56d3fe500 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sat, 24 Sep 2022 02:15:53 +0200 Subject: * lisp/emacs-lisp/shortdoc.el (file-name): Improve examples. --- lisp/emacs-lisp/shortdoc.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lisp/emacs-lisp/shortdoc.el') diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index 2472479bad6..fe4f2ae3acf 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -357,11 +357,9 @@ A FUNC form can have any number of `:no-eval' (or `:no-value'), :eg-result "~some-user") (file-parent-directory :eval (file-parent-directory "/foo/bar") - :eval (file-parent-directory "~") - :eval (file-parent-directory "/tmp/") + :eval (file-parent-directory "/foo/") :eval (file-parent-directory "foo/bar") - :eval (file-parent-directory "foo") - :eval (file-parent-directory "/")) + :eval (file-parent-directory "foo")) "Quoted File Names" (file-name-quote :args (name) -- cgit v1.2.3 From bbd7059da4555586ecedd091cf8a223086bd6201 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 24 Sep 2022 12:44:44 +0200 Subject: Rename file-name-directory * lisp/emacs-lisp/shortdoc.el (file-name): * doc/lispref/files.texi (Directory Names): Adjust. * lisp/files.el (file-name-parent-directory): Rename from `file-name-directory' (bug#58039). --- doc/lispref/files.texi | 2 +- etc/NEWS | 2 +- lisp/emacs-lisp/shortdoc.el | 10 +++++----- lisp/files.el | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'lisp/emacs-lisp/shortdoc.el') diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index 986fb22c75b..e1aa2de523c 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi @@ -2445,7 +2445,7 @@ You can use this function for directory names and for file names, because it recognizes abbreviations even as part of the name. @end defun -@defun file-parent-directory filename +@defun file-name-parent-directory filename This function returns the directory name of the parent directory of @var{filename}. If @var{filename} is at the root directory of the filesystem, it returns @code{nil}. A relative @var{filename} is diff --git a/etc/NEWS b/etc/NEWS index 0d69e87907e..ff97c2350f2 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -482,7 +482,7 @@ user option 'global-text-scale-adjust-resizes-frames' controls whether the frames are resized when the font size is changed. +++ -** New function 'file-parent-directory'. +** New function 'file-name-parent-directory'. Get the parent directory of a file. ** New config variable 'syntax-wholeline-max' to reduce the cost of long lines. diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index fe4f2ae3acf..d07d1019b4d 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -355,11 +355,11 @@ A FUNC form can have any number of `:no-eval' (or `:no-value'), (abbreviate-file-name :no-eval (abbreviate-file-name "/home/some-user") :eg-result "~some-user") - (file-parent-directory - :eval (file-parent-directory "/foo/bar") - :eval (file-parent-directory "/foo/") - :eval (file-parent-directory "foo/bar") - :eval (file-parent-directory "foo")) + (file-name-parent-directory + :eval (file-name-parent-directory "/foo/bar") + :eval (file-name-parent-directory "/foo/") + :eval (file-name-parent-directory "foo/bar") + :eval (file-name-parent-directory "foo")) "Quoted File Names" (file-name-quote :args (name) diff --git a/lisp/files.el b/lisp/files.el index 7fde8720fa7..1e1ec6127de 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5173,7 +5173,7 @@ On most systems, this will be true: (setq filename nil)))) components)) -(defun file-parent-directory (filename) +(defun file-name-parent-directory (filename) "Return the directory name of the parent directory of FILENAME. If FILENAME is at the root of the filesystem, return nil. If FILENAME is relative, it is interpreted to be relative -- cgit v1.2.3 From 3af2f9cce312a2e9fff1bfc5f7689c5b9db369bd Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sun, 25 Sep 2022 13:22:17 +0200 Subject: Bind "N"/"P" to next/prev section in shortdoc * lisp/emacs-lisp/shortdoc.el (shortdoc-mode-map): Bind "N" and "P" to 'shortdoc-next-section' and 'shortdoc-previous-section'. --- etc/NEWS | 6 ++++++ lisp/emacs-lisp/shortdoc.el | 2 ++ 2 files changed, 8 insertions(+) (limited to 'lisp/emacs-lisp/shortdoc.el') diff --git a/etc/NEWS b/etc/NEWS index 835fcf8bcaf..139e65a4f19 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1712,6 +1712,12 @@ This fills the region to be no wider than a specified pixel width. This will take you to the gnu.org web server's version of the current info node. This command only works for the Emacs and Emacs Lisp manuals. +** Shortdoc + +--- +*** 'N' and 'P' are now bound to 'shortdoc-(next|previous)-section'. +This is in addition to the old keybindings 'C-c C-n' and 'C-c C-p'. + ** VC --- diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index d07d1019b4d..13d99adcf08 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -1512,6 +1512,8 @@ Example: :doc "Keymap for `shortdoc-mode'." "n" #'shortdoc-next "p" #'shortdoc-previous + "N" #'shortdoc-next-section + "P" #'shortdoc-previous-section "C-c C-n" #'shortdoc-next-section "C-c C-p" #'shortdoc-previous-section) -- cgit v1.2.3 From e5896907813a9540d0a6b3e60f682afd273fc8e9 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sun, 25 Sep 2022 13:48:12 +0200 Subject: Add new command 'shortdoc-copy-function-as-kill' * lisp/emacs-lisp/shortdoc.el (shortdoc-copy-function-as-kill): New command. (shortdoc-mode-map): Bind above new command to "w". --- etc/NEWS | 4 ++++ lisp/emacs-lisp/shortdoc.el | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'lisp/emacs-lisp/shortdoc.el') diff --git a/etc/NEWS b/etc/NEWS index 139e65a4f19..0a5b7bc29c5 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1714,6 +1714,10 @@ info node. This command only works for the Emacs and Emacs Lisp manuals. ** Shortdoc +--- +*** New command 'shortdoc-copy-function-as-kill' bound to 'w'. +It copies the name of the function near point into the kill ring. + --- *** 'N' and 'P' are now bound to 'shortdoc-(next|previous)-section'. This is in addition to the old keybindings 'C-c C-n' and 'C-c C-p'. diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index 13d99adcf08..33106808d28 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -1515,7 +1515,8 @@ Example: "N" #'shortdoc-next-section "P" #'shortdoc-previous-section "C-c C-n" #'shortdoc-next-section - "C-c C-p" #'shortdoc-previous-section) + "C-c C-p" #'shortdoc-previous-section + "w" #'shortdoc-copy-function-as-kill) (define-derived-mode shortdoc-mode special-mode "shortdoc" "Mode for shortdoc." @@ -1557,6 +1558,20 @@ With ARG, do it that many times." (shortdoc--goto-section arg 'shortdoc-section t) (forward-line -2)) +(defun shortdoc-copy-function-as-kill () + "Copy name of the function near point into the kill ring." + (interactive) + (save-excursion + (goto-char (pos-bol)) + (when-let* ((re (rx bol "(" (group (+ (not (in " ")))))) + (string + (and (or (looking-at re) + (re-search-backward re nil t)) + (match-string 1)))) + (set-text-properties 0 (length string) nil string) + (kill-new string) + (message string)))) + (provide 'shortdoc) ;;; shortdoc.el ends here -- cgit v1.2.3 From 971566e88a9fdb414b3c821cb55a7fc0e903eeba Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sun, 25 Sep 2022 13:54:37 +0200 Subject: Fix shortdoc movement commands * lisp/emacs-lisp/shortdoc.el (shortdoc--goto-section): Don't skip over current function or section when searching. --- lisp/emacs-lisp/shortdoc.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/emacs-lisp/shortdoc.el') diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index 33106808d28..b5c99cf2c9a 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -1529,7 +1529,7 @@ Example: (funcall (if reverse 'text-property-search-backward 'text-property-search-forward) - sym nil t t) + sym nil t) (setq arg (1- arg)))) (defun shortdoc-next (&optional arg) -- cgit v1.2.3 From 489bca19b7a55ba00dbc1d917cd8832268cebcee Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sun, 25 Sep 2022 14:26:40 +0200 Subject: Improve shortdoc documentation * doc/emacs/help.texi (Name Help): * doc/lispref/help.texi (Documentation Groups): Refer to 'shortdoc' convenience alias instead of 'shortdoc-display-group'. * lisp/emacs-lisp/shortdoc.el: Add Commentary. (shortdoc-next, shortdoc-previous) (shortdoc-next-section, shortdoc-previous-section): Doc fixes. --- doc/emacs/help.texi | 9 ++++----- doc/lispref/help.texi | 2 +- lisp/emacs-lisp/shortdoc.el | 25 +++++++++++++++++-------- 3 files changed, 22 insertions(+), 14 deletions(-) (limited to 'lisp/emacs-lisp/shortdoc.el') diff --git a/doc/emacs/help.texi b/doc/emacs/help.texi index 84b082825c2..6d9c028b742 100644 --- a/doc/emacs/help.texi +++ b/doc/emacs/help.texi @@ -311,12 +311,11 @@ doc string to display. In that case, if to load the file in which the function is defined to see whether there's a doc string there. -@findex shortdoc-display-group +@findex shortdoc You can get an overview of functions relevant for a particular topic -by using the @kbd{M-x shortdoc-display-group} command. This will -prompt you for an area of interest, e.g., @code{string}, and pop you -to a buffer where many of the functions relevant for handling strings -are listed. +by using the @kbd{M-x shortdoc} command. This will prompt you for an +area of interest, e.g., @code{string}, and pop you to a buffer where +many of the functions relevant for handling strings are listed. @kindex C-h v @findex describe-variable diff --git a/doc/lispref/help.texi b/doc/lispref/help.texi index 154a7abeb63..65ad5f05542 100644 --- a/doc/lispref/help.texi +++ b/doc/lispref/help.texi @@ -827,7 +827,7 @@ if the user types the help character again. Emacs can list functions based on various groupings. For instance, @code{string-trim} and @code{mapconcat} are ``string'' functions, so -@kbd{M-x shortdoc-display-group RET string RET} will give an overview +@kbd{M-x shortdoc RET string RET} will give an overview of functions that operate on strings. The documentation groups are created with the diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index b5c99cf2c9a..6d61ed4ac16 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -22,6 +22,15 @@ ;;; Commentary: +;; This package lists functions based on various groupings. +;; +;; For instance, `string-trim' and `mapconcat' are `string' functions, +;; so `M-x shortdoc RET string RET' will give an overview of functions +;; that operate on strings. +;; +;; The documentation groups are created with the +;; `define-short-documentation-group' macro. + ;;; Code: (require 'seq) @@ -1533,27 +1542,27 @@ Example: (setq arg (1- arg)))) (defun shortdoc-next (&optional arg) - "Move cursor to the next function. -With ARG, do it that many times." + "Move point to the next function. +With prefix argument ARG, do it that many times." (interactive "p" shortdoc-mode) (shortdoc--goto-section arg 'shortdoc-function)) (defun shortdoc-previous (&optional arg) - "Move cursor to the previous function. -With ARG, do it that many times." + "Move point to the previous function. +With prefix argument ARG, do it that many times." (interactive "p" shortdoc-mode) (shortdoc--goto-section arg 'shortdoc-function t) (backward-char 1)) (defun shortdoc-next-section (&optional arg) - "Move cursor to the next section. -With ARG, do it that many times." + "Move point to the next section. +With prefix argument ARG, do it that many times." (interactive "p" shortdoc-mode) (shortdoc--goto-section arg 'shortdoc-section)) (defun shortdoc-previous-section (&optional arg) - "Move cursor to the previous section. -With ARG, do it that many times." + "Move point to the previous section. +With prefix argument ARG, do it that many times." (interactive "p" shortdoc-mode) (shortdoc--goto-section arg 'shortdoc-section t) (forward-line -2)) -- cgit v1.2.3 From 76b7a593675c95910881b6551b94ddd23f3b1656 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sun, 25 Sep 2022 22:49:32 +0300 Subject: ; Clarify wording of some doc strings in shortdoc.el * lisp/emacs-lisp/shortdoc.el (shortdoc-next, shortdoc-previous) (shortdoc-next-section, shortdoc-previous-section): Clarify wording. --- lisp/emacs-lisp/shortdoc.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lisp/emacs-lisp/shortdoc.el') diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index 6d61ed4ac16..4cfd658e10d 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -1543,26 +1543,26 @@ Example: (defun shortdoc-next (&optional arg) "Move point to the next function. -With prefix argument ARG, do it that many times." +With prefix numeric argument ARG, do it that many times." (interactive "p" shortdoc-mode) (shortdoc--goto-section arg 'shortdoc-function)) (defun shortdoc-previous (&optional arg) "Move point to the previous function. -With prefix argument ARG, do it that many times." +With prefix numeric argument ARG, do it that many times." (interactive "p" shortdoc-mode) (shortdoc--goto-section arg 'shortdoc-function t) (backward-char 1)) (defun shortdoc-next-section (&optional arg) "Move point to the next section. -With prefix argument ARG, do it that many times." +With prefix numeric argument ARG, do it that many times." (interactive "p" shortdoc-mode) (shortdoc--goto-section arg 'shortdoc-section)) (defun shortdoc-previous-section (&optional arg) "Move point to the previous section. -With prefix argument ARG, do it that many times." +With prefix numeric argument ARG, do it that many times." (interactive "p" shortdoc-mode) (shortdoc--goto-section arg 'shortdoc-section t) (forward-line -2)) -- cgit v1.2.3