branch: scratch/hyperbole-lexbind commit 0829631c9c2485d78b6f588b41d1f0c54b00a119 Author: Bob Weiner <r...@gnu.org> Commit: Bob Weiner <r...@gnu.org>
Fix small logic errors in new e/g/ilink functions --- Changes | 6 ++++++ hactypes.el | 36 ++++++++++++++++++++---------------- hbut.el | 4 ++-- hibtypes.el | 15 +++++++++------ 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/Changes b/Changes index 0815d4e..1712e2d 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,9 @@ +2019-07-14 Bob Weiner <r...@gnu.org> + +* hibtypes.el (link-to-ebut, link-to-gbut, link-to-ibut): + hactypes.el (link-to-ibut): + hbut.el (ibut:to): Fixed small logic errors with lbl-keys and save-excursion in these functions. + 2019-07-13 Bob Weiner <r...@gnu.org> * hsys-org.el (org-set-ibut-label): Added and used in org-mode ibtype. diff --git a/hactypes.el b/hactypes.el index d227faa..911a1c7 100644 --- a/hactypes.el +++ b/hactypes.el @@ -392,29 +392,33 @@ available. Filename may be given without the .info suffix." (id-info string) (hypb:error "(link-to-Info-node): Invalid Info node: `%s'" string))) -(defact link-to-ibut (key-file key &optional point) +(defact link-to-ibut (key &optional key-file point) "Performs action given by an implicit button, specified by KEY-FILE, KEY and optional POINT. When creating the button, point must be on the implicit button to which to link and its buffer must have a file attached." (interactive (let ((ibut-key (ibut:at-p t))) (if (and ibut-key buffer-file-name) - (list buffer-file-name ibut-key (point)) + (list ibut-key buffer-file-name (point)) (list nil nil nil)))) - (or (called-interactively-p 'interactive) - (setq key-file (hpath:validate (hpath:substitute-value key-file)))) - (let (but) - (if (and key-file - (save-excursion - (save-restriction - (find-file-noselect key-file) - (widen) - (if (integerp point) (goto-char (min point (point-max)))) - (setq but (ibut:to key))))) - (hbut:act but) - (hypb:error "(link-to-ibut): No button `%s' in `%s'." - (ibut:key-to-label key) - key-file)))) + (if key-file + (or (called-interactively-p 'interactive) + (null key-file) + (setq key-file (hpath:validate (hpath:substitute-value key-file)))) + (setq key-file buffer-file-name)) + (save-excursion + (save-restriction + (let (but) + (when key-file + (find-file-noselect key-file)) + (widen) + (if (integerp point) (goto-char (min point (point-max)))) + (setq but (ibut:to key))))) + (if but + (hbut:act but) + (hypb:error "(link-to-ibut): No button `%s' in `%s'." + (ibut:key-to-label key) + (or key-file (buffer-name))))) (defact link-to-kcell (file cell-ref) "Displays FILE with kcell given by CELL-REF at window top. diff --git a/hbut.el b/hbut.el index cc71510..c927647 100644 --- a/hbut.el +++ b/hbut.el @@ -1309,11 +1309,11 @@ move to the first occurrence of the button." (forward-line 0) ;; re-search forward (while (and (not found) (re-search-forward regexp nil t)) - (setq pos (goto-char (match-beginning 0)) + (setq pos (match-beginning 0) found (equal (ibut:at-p t) lbl-key))) ;; re-search backward (while (and (not found) (re-search-backward regexp nil t)) - (setq pos (goto-char (match-beginning 0)) + (setq pos (match-beginning 0) found (equal (ibut:at-p t) lbl-key)))) (when found (goto-char pos) diff --git a/hibtypes.el b/hibtypes.el index dd09470..c3eefad 100644 --- a/hibtypes.el +++ b/hibtypes.el @@ -642,12 +642,13 @@ The explicit button's action is executed in the context of the current buffer. Recognizes the format '<elink:' <button label> '>', e.g. <elink: project-list>." (let* ((label-key-start-end (hbut:label-p nil elink:start elink:end t t)) - (lbl-key (nth 0 label-key-start-end)) + (ebut-key (nth 0 label-key-start-end)) + (lbl-key (and ebut-key (concat "elink_" (nth 0 label-key-start-end)))) (start-pos (nth 1 label-key-start-end)) (end-pos (nth 2 label-key-start-end))) (when lbl-key (ibut:label-set (ebut:key-to-label lbl-key) start-pos end-pos) - (hact 'link-to-ebut lbl-key)))) + (hact 'link-to-ebut ebut-key)))) (defconst glink:start "<glink:" "String matching the start of a link to a Hyperbole global button.") @@ -660,12 +661,13 @@ The global button's action is executed in the context of the current buffer. Recognizes the format '<glink:' <button label> '>', e.g. <glink: open todos>." (let* ((label-key-start-end (hbut:label-p nil glink:start glink:end t t)) - (lbl-key (nth 0 label-key-start-end)) + (gbut-key (nth 0 label-key-start-end)) + (lbl-key (and gbut-key (concat "glink_" (nth 0 label-key-start-end)))) (start-pos (nth 1 label-key-start-end)) (end-pos (nth 2 label-key-start-end))) (when lbl-key (ibut:label-set (ebut:key-to-label lbl-key) start-pos end-pos) - (hact 'link-to-gbut lbl-key)))) + (hact 'link-to-gbut gbut-key)))) (defconst ilink:start "<ilink:" "String matching the start of a link to a Hyperbole implicit button.") @@ -678,12 +680,13 @@ The implicit button's action is executed in the context of the current buffer. Recognizes the format '<ilink:' <button label> '>', e.g. <ilink: my sequence of keys>." (let* ((label-key-start-end (ibut:label-p nil ilink:start ilink:end t t)) - (lbl-key (nth 0 label-key-start-end)) + (ibut-key (nth 0 label-key-start-end)) + (lbl-key (and ibut-key (concat "ilink_" (nth 0 label-key-start-end)))) (start-pos (nth 1 label-key-start-end)) (end-pos (nth 2 label-key-start-end))) (when lbl-key (ibut:label-set (ibut:key-to-label lbl-key) start-pos end-pos) - (hact 'link-to-ibut lbl-key)))) + (hact 'link-to-ibut ibut-key)))) ;;; ======================================================================== ;;; Jumps to source line associated with ipython, ripgreb, grep or