commit a80d437444365c6a7a03ed82fc5bacb64efd8bce
parent 4b72bd743fd8110d1d39e1b2db958264e872d255
Author: Lou Woell <lou.woell@posteo.de>
Date:   Sat, 13 Sep 2025 22:27:47 +0200

[haredoc.el] make references clickable links

Diffstat:
Mharedoc.el | 37++++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/haredoc.el b/haredoc.el @@ -32,6 +32,7 @@ ;;; Code: (require 'f) +(require 'button) (require 'project) (require 'thingatpt) (require 'ansi-color) @@ -64,13 +65,43 @@ "resolve" id (buffer-file-name))))) +(define-button-type 'haredoc + 'follow-link t + 'action #'haredoc/button-action + 'help-echo (purecopy "mouse-2, RET: describe this")) + +(defun haredoc/button-action (button) + (let* ((name (button-get button :args)) + (module (button-get button :module)) + (namespace? (string-match-p ".*::.*" name)) + (target (if namespace? name + (string-join (list module name) "::")))) + (haredoc target))) + +(defun haredoc/make-button (match-number module) + (make-button (match-beginning match-number) + (match-end match-number) + :type 'haredoc + :module module + :args (match-string match-number))) + ;; Shows haredoc for the selected or word. ;;;###autoload (defun haredoc (&optional sign) "Run haredoc with the current word under the cursor and display the results in a new buffer." (interactive) - (let ((current-word (or sign (haredoc/read-module)))) + (let* ((current-word (or sign (haredoc/read-module))) + (components (string-split current-word "::" t)) + (cmps (length components)) + (location (haredoc/get-location current-word)) + (location (string-split location ":" t)) + (path (nth 0 location)) + (line (string-to-number (nth 1 location))) + (col (string-to-number (nth 2 location))) + (module? (= col line 0)) + (namespace (if module? current-word + (string-join (butlast components) "::")))) (with-current-buffer-window "*haredoc*" 'display-buffer-pop-up-window nil (insert "\033[1;4m" current-word "\033[0m\n\n") @@ -80,6 +111,10 @@ the results in a new buffer." "-P")))) (call-process "haredoc" nil t nil "-a" "-F" "tty" current-word)) (ansi-color-apply-on-region (point-min) (point-max)) + (save-excursion + (goto-char (point-min)) + (while (re-search-forward "\\[\\[\\(.*?\\)\\]\\]" nil t) + (haredoc/make-button 1 namespace))) (haredoc-mode)))) ;;;###autoload