[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#16333: 24.3.50; Info manuals: link defined terms to their glossary e
From: |
Drew Adams |
Subject: |
bug#16333: 24.3.50; Info manuals: link defined terms to their glossary entries |
Date: |
Fri, 30 Oct 2020 14:14:54 -0700 (PDT) |
> Here's a suggestion, to make this less rigid/fragile:
> Substitute for "mouse-2" everywhere in the help text,
> as follows.
>
> (defun mouse-fixup-help-message (msg)
> "Fix help message MSG for `mouse-1-click-follows-link'."
> (let (mp pos)
> (when (and mouse-1-click-follows-link
> (stringp msg)
> (string-match-p "mouse-2" msg)
> (setq mp (mouse-pixel-position))
> (consp (setq pos (cdr mp)))
> (car pos) (>= (car pos) 0)
> (cdr pos) (>= (cdr pos) 0)
> (setq pos (posn-at-x-y (car pos) (cdr pos) (car mp)))
> (windowp (posn-window pos)))
> (with-current-buffer (window-buffer (posn-window pos))
> (when (mouse-on-link-p pos)
> (setq msg (replace-regexp-in-string
> "mouse-2"
> (concat
> (cond ((eq mouse-1-click-follows-link 'double)
> "double-")
> ((and (integerp mouse-1-click-follows-link)
> (< mouse-1-click-follows-link 0))
> "Long ")
> (t ""))
> "mouse-1")
> msg))))))
> msg)
> ___
>
> Or if you think it's more appropriate for some reason,
> then substitute only the first occurrence of "mouse-2".
>
> Of if you think we should let users specify exactly
> which occurrences of "mouse-2" to substitute, then
> define a formatting escape for that (e.g. "%m"), so
> only "mouse-2" occurrences preceded by that escape get
> substituted. E.g., "xxx%mmouse-2" would substitute
> the "mouse-2", but "xxxmouse-2" would not.
Actually, the following is much better. It lets code
use different patterns in different contexts, by binding
the variable.
Should I submit this as a separate bug report, or can it
be considered in the context of this one?
(defvar mouse-fixup-help-replace-regexp
'("\\(?:\\|[[:space:]]\\)\\(mouse-2\\)" . 1)
"Regexp to match \"mouse-2\" in MSG.
The value is a cons (REGEXP . N). Function `mouse-fixup-help-message'
replaces the match of subexpression N, of the text that matches
REGEXP, with \"mouse-1\".")
(defun mouse-fixup-help-message (msg)
"Fix help message MSG for `mouse-1-click-follows-link'."
(let (mp pos)
(when (and mouse-1-click-follows-link
(stringp msg)
(string-match-p "mouse-2" msg)
(setq mp (mouse-pixel-position))
(consp (setq pos (cdr mp)))
(car pos) (>= (car pos) 0)
(cdr pos) (>= (cdr pos) 0)
(setq pos (posn-at-x-y (car pos) (cdr pos) (car mp)))
(windowp (posn-window pos)))
(with-current-buffer (window-buffer (posn-window pos))
(when (mouse-on-link-p pos)
(setq msg (replace-regexp-in-string
(car mouse-fixup-help-replace-regexp)
(concat
(cond ((eq mouse-1-click-follows-link 'double)
"double-")
((and (integerp mouse-1-click-follows-link)
(< mouse-1-click-follows-link 0))
"Long ")
(t ""))
"mouse-1")
msg nil nil (cdr mouse-fixup-help-replace-regexp)))))))
msg)
bug#16333: 24.3.50; Info manuals: link defined terms to their glossary entries, Stefan Kangas, 2020/10/29