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'.
---
*** New command 'outline-xref'.
It allows users to navigate the current buffer's outline using Xref.
It is bound to 'M-o'.
*** New command 'outline-find-headings'.
It finds all outline headings in the current buffer and displays them in
an Xref buffer. Users can use that Xref buffer to navigate and edit the
outline. It is bound to 'M-o'.
** Xref

View file

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

View file

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