Closed jeremyf closed 3 years ago
I did some quick hacking and the following appears "adequate" for shrface-headlines-consult
.
(defun shrface-headlines-consult ()
"Use consult to show all headlines in order founded in the buffer.
Current headline will be the one of the candidates to initially select."
(interactive)
(let ((current (point-min)) (start (1+ (point))) point number)
;; Scan from point-min to (1+ (point)) to find the current headline.
;; (1+ (point)) to include under current point headline into the scan range.
(unless (> start (point-max))
(while (setq point (text-property-not-all
current start shrface-headline-number-property nil))
(setq current (1+ point))))
(cond ((equal (point) 1) (setq number 0))
((equal (point) 2) (setq number 0))
((equal (point) (point-max)) (setq number 0))
(t
(ignore-errors (setq number (1- (get-text-property (1- current) shrface-headline-number-property))))))
;; Start the consult--read
(setq start (point)) ; save the starting point
(if (fboundp 'consult--read)
(consult--read (shrface-headline-selectable-list)
:prompt "shrface headline:"
:category 'shrface-headlines-consult
:sort nil)
(message "Please install 'consult' before using 'shrface-headlines-consult'"))))
Note, the preamble before the ;; Start the consult--read
is copied from shrface-headlines-consult
And then the shrface-links-consult
:
(defun shrface-links-consult ()
"Use consult to present all urls in order founded in the buffer."
(interactive)
(let ((start (point)) next url)
;; get the next nearest url
(setq next (text-property-not-all
(point) (point-max) shrface-href-follow-link-property nil))
;; only if the next url exists
(if next
(setq url (get-text-property next shrface-href-property)))
(if (fboundp 'consult--read)
(consult--read (shrface-links-selectable-list)
:prompt "shrface link:"
:category 'shrface-links-consult
:sort nil)
(message "Please install 'consult' before using 'shrface-links-consult'"))))
These appear to work in a simple case.
I did not have experience to use consult, would you help submit a pull request? I am willing to add it.
First, I stumbled upon this package, and I appreciate the work you've done to get the EWW headings to render in IMenu. That's a great add for quick navigation.
I'm wondering if you'd consider adding a
shrface-links-consult
andshrface-headlines-consult
that would echoshrface-links-counsel
andshrface-headlines-counsel
. I've been using the Consult package and by my read of /r/emacs, the Consult package is gaining in popularity.The consult--read function appears to be the analogue to
ivy-read
. Thanks in advance for your consideration!