Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
2026-03-01 Bob Weiner <rsw@gnu.org>

* hywiki.el (hywiki-maybe-highlight-references): Fix to include #section
spaces only if the delimiter is at the start of the WikiWord ref.
(hywiki--end-pos): Add and set in 'hywiki-completion-at-point'
to pass to 'hywiki-completion-exit-function'. This handles when point
is moved to before the completion prefix, it is cancelled and the exit
function should not insert anything or move point any further.
(hywiki-completion-at-point): Fix completion after # suffix by
stripping the suffix off the WikiWord ref when used as the page name
in the grep 'cmd'.
(hywiki-word-at): Make char after # optional so when doing
completion and # is followed by a closing delimiter, it does not stop
completing because of failure to recognize the WikiWord reference.

2026-02-28 Bob Weiner <rsw@gnu.org>

* hyrolo.el (hyrolo-mode): Make the match buffer's 'hyrolo-mode' a special
mode. HyWiki buttons will never be active therein since every name
would trigger as a new, potential HyWiki word.

2026-02-28 Mats Lidell <matsl@gnu.org>

* test/hywiki-tests.el (hywiki-tests--get-page-headings):
Expand Down Expand Up @@ -33,7 +54,7 @@
first or the difference will always be nil.
hsys-consult.el (hsys-consult-require-version): Add to make 'hsys-consult-flag'
and this version check callable from other libraries.
(hsys-consult-grep, hsys-consult--grep-paths): Call above
(hsys-consult-grep, hsys-consult--grep-paths): Call above
new function.

* hywiki.el (hywiki-consult-page-and-headline): Call above new function.
Expand Down
4 changes: 3 additions & 1 deletion hyrolo.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 7-Jun-89 at 22:08:29
;; Last-Mod: 30-Dec-25 at 14:42:32 by Mats Lidell
;; Last-Mod: 28-Feb-26 at 23:10:24 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -2253,6 +2253,8 @@ Calls the functions given by `hyrolo-mode-hook'.
\\{hyrolo-mode-map}"
(interactive)
(unless (eq major-mode 'hyrolo-mode)
;; The mode controls the data in its buffers and it is non-editable
(put 'hyrolo-mode 'mode-class 'special)
(push (cons (substring hyrolo-hdr-regexp 1) 1) outline-heading-alist)
(push (cons (if (boundp 'hbut:source-prefix)
hbut:source-prefix
Expand Down
60 changes: 39 additions & 21 deletions hywiki.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 21-Apr-24 at 22:41:13
;; Last-Mod: 28-Feb-26 at 15:37:59 by Bob Weiner
;; Last-Mod: 1-Mar-26 at 01:28:37 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -198,12 +198,13 @@ checks it to determine if any buffer modification has occurred or not.")
Each such key self-inserts before highlighting any prior HyWikiWord
in `hywiki-mode'.")

(defvar hywiki--delimiter-hasht (hash-make '(("\"" . ?\")
("\'" . ?\')
("{" . ?})
("[" . ?\])
("<" . ?>)
("(" . ?\))) t)
(defconst hywiki--delimiter-hasht (hash-make '(("\"" . ?\")
("\'" . ?\')
("{" . ?})
("[" . ?\])
("<" . ?>)
("(" . ?\)))
t)
"Delimiter htable with (open-delim-string . close-delim-char) key-value pairs.")

(defvar hywiki--directory-checksum ""
Expand Down Expand Up @@ -255,6 +256,7 @@ Group 1 is the entire HyWikiWord#section:Lnum:Cnum expression.")
(defvar-local hywiki--buttonize-start (make-marker)) ;; This must always stay a marker
(defvar-local hywiki--buttonize-range nil)
(defvar-local hywiki--char-before nil)
(defvar-local hywiki--end-pos nil)
(defvar-local hywiki--end nil)
(defvar-local hywiki--range nil)
(defvar-local hywiki--start nil)
Expand Down Expand Up @@ -1496,6 +1498,7 @@ exists."
(defun hywiki-completion-at-point ()
"Complete a HyWiki reference at point.
Each candidate is an alist with keys: file, line, text, and display."
(setq hywiki--end-pos nil)
(let* ((ref-start-end (and (hywiki-active-in-current-buffer-p)
(not (hywiki-non-hook-context-p))
(hywiki-word-at t t)))
Expand All @@ -1505,7 +1508,7 @@ Each candidate is an alist with keys: file, line, text, and display."
(when start
(let* ((default-directory hywiki-directory)
(cmd (format "grep -nEH '^([ \t]*\\*+|#\\+TITLE:) +' ./*%s*%s"
(regexp-quote ref)
(hywiki-word-strip-suffix ref)
hywiki-file-suffix))
(output (shell-command-to-string cmd))
(lines (split-string output "\n" t))
Expand All @@ -1515,7 +1518,8 @@ Each candidate is an alist with keys: file, line, text, and display."
(nconc (hywiki-get-page-list)
(mapcar #'hywiki-format-grep-to-reference lines))))))
(when candidate-alist
(setq hywiki--char-before (char-before start))
(setq hywiki--char-before (char-before start)
hywiki--end-pos end)
(list start end candidate-alist
:exclusive 'no
;; For company, allow any non-delim chars in prefix
Expand Down Expand Up @@ -2703,11 +2707,23 @@ whenever `hywiki-mode' is enabled/disabled."
(skip-syntax-forward "^-\)$\>._\"\'"))
(skip-chars-forward "-_*[:alnum:]")
(unless (zerop (skip-chars-forward "#:"))
(skip-chars-forward (if (save-restriction
(widen)
(hywiki-delimited-p))
"-_*: \t[:alnum:]"
"-_*:[:alnum:]")))
(skip-chars-forward
(if (save-restriction
(widen)
(and (hywiki-delimited-p)
;; Only if delimiter is
;; the char preceding
;; the start of the
;; WikiWord do we skip
;; over spaces to find
;; the #section.
(hash-get
(char-to-string
(or (char-before (or hywiki--start 0))
0))
hywiki--delimiter-hasht)))
"-_*: \t[:alnum:]"
"-_*:[:alnum:]")))
(setq hywiki--end (point))
;; Don't highlight current-page matches unless they
;; include a #section.
Expand Down Expand Up @@ -3575,7 +3591,7 @@ non-nil or this will return nil."
(hywiki-maybe-at-wikiword-beginning))
(looking-at (concat
hywiki-word-regexp
"\\(#[^][#()<>{}\" \t\n\r\f]+\\)?"
"\\(#[^][#()<>{}\" \t\n\r\f]*\\)?"
hywiki-word-line-and-column-numbers-regexp "?"))
;; Can't be followed by a # character
(/= (or (char-after (match-end 0)) 0)
Expand Down Expand Up @@ -3966,12 +3982,14 @@ occurs with one of these hooks, the problematic hook is removed."
(let ((end-delim (when (characterp hywiki--char-before)
(hash-get (char-to-string hywiki--char-before)
hywiki--delimiter-hasht))))
(if (and end-delim
(or (>= (point) (point-max))
(not (eq (char-after (point)) end-delim))))
(progn (insert end-delim)
(goto-char (- (point) 2)))
(goto-char (1- (point)))))
(when (and hywiki--end-pos
(>= (point) hywiki--end-pos))
(if (and end-delim
(or (>= (point) (point-max))
(not (eq (char-after (point)) end-delim))))
(progn (insert end-delim)
(goto-char (- (point) 2)))
(when end-delim (goto-char (1- (point)))))))
(hywiki-maybe-highlight-reference))

(defun hywiki-word-add-completion-at-point ()
Expand Down