Rename outline-xref' command to outline-find-headings'

* etc/NEWS: Update entry.
* lisp/outline.el (outline-mode-prefix-map, outline-mode-menu-bar-map):
Use `outline-find-headings'.
(outline-find-headings--fetch-xrefs): Rename from
`outline-xref--fetch-headings'.
(outline-find-headings--show-xrefs): Rename from
`outline-xref--show-xrefs'.
(outline-find-headings): Rename from `outline-xref'.
* test/lisp/outline-tests.el
(outline-tests--outline-find-headings-search-function): Rename from
`outline-tests--outline-xref-search-function'.
(outline-tests--outline-find-headings-regexp): Rename from
`outline-tests--outline-xref-regexp'.
(outline-tests--outline-find-headings-undefined): Rename from
`outline-tests--outline-xref-undefined'.  (Bug#81592)
This commit is contained in:
Roi Martin 2026-09-04 11:00:47 +02:00 committed by Dmitry Gutov
parent ae474d3864
commit e33b54d938
3 changed files with 26 additions and 26 deletions

View file

@ -281,9 +281,10 @@ Otherwise, a pattern is built from 'comment-start' and the new option
'outline-comment-regexp-suffix'. 'outline-comment-regexp-suffix'.
--- ---
*** New command 'outline-xref'. *** New command 'outline-find-headings'.
It allows users to navigate the current buffer's outline using Xref. It finds all outline headings in the current buffer and displays them in
It is bound to 'M-o'. an Xref buffer. Users can use that Xref buffer to navigate and edit the
outline. It is bound to 'M-o'.
** Xref ** Xref

View file

@ -109,7 +109,7 @@ imitate the function `looking-at'."
"C-<" #'outline-promote "C-<" #'outline-promote
"C->" #'outline-demote "C->" #'outline-demote
"RET" #'outline-insert-heading "RET" #'outline-insert-heading
"M-o" #'outline-xref) "M-o" #'outline-find-headings)
(defvar outline-mode-menu-bar-map (defvar outline-mode-menu-bar-map
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
@ -150,9 +150,9 @@ imitate the function `looking-at'."
:help "Show all of the text in the buffer")) :help "Show all of the text in the buffer"))
(define-key map [headings] (define-key map [headings]
(cons "Headings" (make-sparse-keymap "Headings"))) (cons "Headings" (make-sparse-keymap "Headings")))
(define-key map [headings outline-xref] (define-key map [headings outline-find-headings]
'(menu-item "Show in Xref" outline-xref '(menu-item "Find All Headings" outline-find-headings
:help "Navigate the buffer's outline using Xref")) :help "Find all outline headings in the buffer"))
(define-key map [headings demote-subtree] (define-key map [headings demote-subtree]
'(menu-item "Demote Subtree" outline-demote '(menu-item "Demote Subtree" outline-demote
:help "Demote headings lower down the tree")) :help "Demote headings lower down the tree"))
@ -2337,7 +2337,7 @@ when comment-heading setup was not performed."
;;; Xref outline navigation ;;; Xref outline navigation
(defun outline-xref--fetch-headings (search-function buffer) (defun outline-find-headings--fetch-xrefs (search-function buffer)
"Return a list of Xref values matching SEARCH-FUNCTION in BUFFER." "Return a list of Xref values matching SEARCH-FUNCTION in BUFFER."
(let (headings) (let (headings)
(with-current-buffer buffer (with-current-buffer buffer
@ -2355,31 +2355,30 @@ when comment-heading setup was not performed."
(forward-line 1)))) (forward-line 1))))
(nreverse headings))) (nreverse headings)))
(defun outline-xref--show-xrefs (search-function) (defun outline-find-headings--show-xrefs (search-function)
"Display search results in an Xref buffer. "Display search results in an Xref buffer.
Populate an Xref buffer with the matches returned by SEARCH-FUNCTION Populate an Xref buffer with the matches returned by SEARCH-FUNCTION
applied to the current buffer." applied to the current buffer."
(let ((buf (current-buffer))) (let ((buf (current-buffer)))
(xref-show-xrefs (xref-show-xrefs
(lambda () (lambda ()
(outline-xref--fetch-headings search-function buf)) (outline-find-headings--fetch-xrefs search-function buf))
nil))) nil)))
;;;###autoload ;;;###autoload
(defun outline-xref () (defun outline-find-headings ()
"Navigate the current buffer's outline using Xref. "Find all outline headings in the current buffer.
Display an Xref buffer with the outline headings found in the current Display an Xref buffer with the outline headings found in the current
buffer. You can use Xref commands in that Xref buffer to navigate and edit buffer. You can use that Xref buffer to navigate and edit the outline.
the outline.
If `outline-search-function' is non-nil, it is used to find the outline If `outline-search-function' is non-nil, it is used to find the outline
headings. Otherwise, the `outline-regexp' variable is used." headings. Otherwise, `outline-regexp' is used."
(interactive) (interactive)
(cond (cond
(outline-search-function (outline-search-function
(outline-xref--show-xrefs outline-search-function)) (outline-find-headings--show-xrefs outline-search-function))
(outline-regexp (outline-regexp
(outline-xref--show-xrefs #'outline-search-from-regexp)) (outline-find-headings--show-xrefs #'outline-search-from-regexp))
(t (t
(user-error "Undefined outline search strategy")))) (user-error "Undefined outline search strategy"))))

View file

@ -27,8 +27,8 @@
(require 'ert-x) (require 'ert-x)
(require 'outline) (require 'outline)
(ert-deftest outline-tests--outline-xref-search-function () (ert-deftest outline-tests--outline-find-headings-search-function ()
"Test the `outline-xref' function with `outline-search-function'." "Test the `outline-find-headings' function with `outline-search-function'."
(let ((test-file (ert-resource-file "outline.txt"))) (let ((test-file (ert-resource-file "outline.txt")))
(with-temp-buffer (with-temp-buffer
(insert-file-contents test-file) (insert-file-contents test-file)
@ -36,35 +36,35 @@
(outline-search-function (outline-search-function
(lambda (&optional bound move _backward _looking-at) (lambda (&optional bound move _backward _looking-at)
(re-search-forward "^-" bound move)))) (re-search-forward "^-" bound move))))
(outline-xref))) (outline-find-headings)))
(with-current-buffer (get-buffer "*xref*") (with-current-buffer (get-buffer "*xref*")
(goto-char (point-min)) (goto-char (point-min))
(should-error (search-forward "* Star heading")) (should-error (search-forward "* Star heading"))
(goto-char (point-min)) (goto-char (point-min))
(should (search-forward "- Dash heading"))))) (should (search-forward "- Dash heading")))))
(ert-deftest outline-tests--outline-xref-regexp () (ert-deftest outline-tests--outline-find-headings-regexp ()
"Test the `outline-xref' function with `outline-regexp'." "Test the `outline-find-headings' function with `outline-regexp'."
(let ((test-file (ert-resource-file "outline.txt"))) (let ((test-file (ert-resource-file "outline.txt")))
(with-temp-buffer (with-temp-buffer
(insert-file-contents test-file) (insert-file-contents test-file)
(let ((outline-regexp "\\*") (let ((outline-regexp "\\*")
(outline-search-function nil)) (outline-search-function nil))
(outline-xref))) (outline-find-headings)))
(with-current-buffer (get-buffer "*xref*") (with-current-buffer (get-buffer "*xref*")
(goto-char (point-min)) (goto-char (point-min))
(should (search-forward "* Star heading")) (should (search-forward "* Star heading"))
(goto-char (point-min)) (goto-char (point-min))
(should-error (search-forward "- Dash heading"))))) (should-error (search-forward "- Dash heading")))))
(ert-deftest outline-tests--outline-xref-undefined () (ert-deftest outline-tests--outline-find-headings-undefined ()
"Test the `outline-xref' function with undefined search strategy." "Test the `outline-find-headings' function with undefined search strategy."
(let ((test-file (ert-resource-file "outline.txt"))) (let ((test-file (ert-resource-file "outline.txt")))
(with-temp-buffer (with-temp-buffer
(insert-file-contents test-file) (insert-file-contents test-file)
(let ((outline-regexp nil) (let ((outline-regexp nil)
(outline-search-function nil)) (outline-search-function nil))
(should-error (outline-xref)))))) (should-error (outline-find-headings))))))
(provide 'outline-tests) (provide 'outline-tests)