branch: externals/hyperbole commit 298fd129ae0f21076d2e775122d72b949c8c44ba Author: Bob Weiner <bob.wei...@duffandphelps.com> Commit: Bob Weiner <bob.wei...@duffandphelps.com>
Add optional key file path argument to e/ilinks --- Changes | 20 +++++++++++++-- HY-NEWS | 8 +++--- README.md.html | 2 +- hactypes.el | 13 ++++++---- hargs.el | 3 ++- hibtypes.el | 78 +++++++++++++++++++++++++++++++++++++--------------------- 6 files changed, 83 insertions(+), 41 deletions(-) diff --git a/Changes b/Changes index 3e41c40..5c6dc15 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,19 @@ +2019-08-26 Bob Weiner <r...@gnu.org> + +* hibtypes.el (hlink, parse-label-and-file): Added to allow for linking + to Hyperbole butttons in other files and used in e/g/ilinks. + +* hargs.el (hargs:delimited): Replaced cl evenp call with zerop and modulo. + hibtypes.el (action): Replaced cl 'find' call with 'string-match-p'. + +* Makefile (dev-install): Removed this target and replaced with 'bin'. Added + 'src' target to setup to run from .el files only. Updated help to explain + how to run test code either from .el or .elc files. + +============================================================================== +V7.0.5 changes ^^^^: +============================================================================== + 2019-08-25 Bob Weiner <r...@gnu.org> * Makefile (HYPERBOLE_FILES): Removed hyperbole-pkg.el and deleted that file @@ -8,9 +24,9 @@ Also, called 'shell' command if existing shell buffer does not have a process and updated buf-name with the buffer returned by the 'shell' command. - (exec-shell-cmd): Applied similar changes. + (exec-shell-cmd): Applied similar changes. -* hpath.el (hpath:find): Changed modifier comparisons to use = and wrapped +* hpath.el (hpath:find): Changed modifier comparisons to use = and wrapped (load filename) in a 'hact' macro. (hpath:is-p): Only temporarily strip any initial execution modifier character from the path so can be handled later by action types. diff --git a/HY-NEWS b/HY-NEWS index 46a4de0..ccb785b 100644 --- a/HY-NEWS +++ b/HY-NEWS @@ -43,11 +43,11 @@ global buttons file (personal button file). - Link to Buttons: New implicit button types that link to button categories: - In Buffer Syntax Implicit Button Type + In Buffer Syntax Implicit Button Type =========================================================================== - <elink: explicit button label to link to> link-to-ebut - <glink: global button label to link to> link-to-gbut - <ilink: implicit button label to link to> link-to-iut + <elink: explicit button label to link to: optional ebut file> link-to-ebut + <glink: global button label to link to> link-to-gbut + <ilink: implicit button label to link to: optional ibut file> link-to-ibut - Other new implicit button types: debugger-source: Jump to the source of errors from the Python pytype package diff --git a/README.md.html b/README.md.html index e62461c..4350368 100644 --- a/README.md.html +++ b/README.md.html @@ -1,5 +1,5 @@ <h1> -<a id="user-content-gnu-hyperbole-703b---the-everyday-hypertextual-information-manager" class="anchor" href="#gnu-hyperbole-703b---the-everyday-hypertextual-information-manager" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>GNU Hyperbole 7.0.3b - The Everyday Hypertextual Information Manager</h1> +<a id="user-content-gnu-hyperbole-704---the-everyday-hypertextual-information-manager" class="anchor" href="#gnu-hyperbole-704---the-everyday-hypertextual-information-manager" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>GNU Hyperbole 7.0.4 - The Everyday Hypertextual Information Manager</h1> <p>[Say thanks if you like Hyperbole.(<a href="https://saythanks.io/to/rswgnu" rel="nofollow">https://saythanks.io/to/rswgnu</a>)]</p> <p><strong>Table of Contents</strong></p> diff --git a/hactypes.el b/hactypes.el index ab9a80e..e0790ef 100644 --- a/hactypes.el +++ b/hactypes.el @@ -363,8 +363,10 @@ the window." (hpath:find-line path line-num)) (move-to-column column-num))) -(defact link-to-gbut (key) - "Perform an action given by an existing global button, specified by KEY." +(defact link-to-gbut (key &optional key-file) + "Perform an action given by an existing global button, specified by KEY. +Optional second arg, KEY-FILE, is not used but is for calling +compatibility from the `hlink' function." (interactive (let ((gbut-file (hpath:validate (hpath:substitute-value gbut:file))) but-lbl) @@ -383,9 +385,10 @@ the window." (defact link-to-Info-index-item (index-item) "Display an Info index INDEX-ITEM cross-reference. -INDEX-ITEM must be a string of the form \"(filename)item-name\". During -button creation, completion for both filename and item-name is -available. Filename may be given without the .info suffix." +INDEX-ITEM must be a string of the form \"(filename)item-name\". +During button creation, completion for both filename and +item-name is available. Filename may be given without the .info +suffix." (interactive "+XInfo (file)index-item-name to link to: ") (require 'info) (if (and (stringp index-item) (string-match "^(\\([^\)]+\\))\\(.*\\)" index-item)) diff --git a/hargs.el b/hargs.el index 09fd98f..f896677 100644 --- a/hargs.el +++ b/hargs.el @@ -128,7 +128,8 @@ With optional EXCLUDE-REGEXP, any matched string is ignored if it this regexp." (funcall end-search-func end-delim opoint t) (setq count (1+ count))) (setq start nil)) - (when (and (not start) (> count 0) (evenp count) (string-equal start-delim end-delim)) + (when (and (not start) (> count 0) (zerop (% count 2)) + (string-equal start-delim end-delim)) ;; Since strings can span lines but this function matches only ;; strings that start on the current line, when start-delim and ;; end-delim are the same and there are an even number of diff --git a/hibtypes.el b/hibtypes.el index a330b0d..51d5f3a 100644 --- a/hibtypes.el +++ b/hibtypes.el @@ -405,7 +405,7 @@ arg1 ... argN '>'. For example, <mail u...@mybiz.com>." (when (string-match "\\`\\$" lbl) (setq var-flag t lbl (substring lbl 1))) - (setq actype (if (find ?\ lbl) (car (split-string lbl)) lbl) + (setq actype (if (string-match-p " " lbl) (car (split-string lbl)) lbl) actype (or (intern-soft (concat "actype::" actype)) (intern-soft actype))) (when actype @@ -699,6 +699,44 @@ Requires the Emacs builtin Tramp library for ftp file retrievals." ;;; Links to Hyperbole button types ;;; ======================================================================== +(defun hlink (link-actype label-prefix start-delim end-delim) + "Call LINK-ACTYPE as the action type and prefix button with LABEL-PREFIX if point is within an implicit button delimited by START-DELIM and END-DELIM." + ;; Used by e/g/ilink implicit buttons." + (let* ((label-start-end (hbut:label-p t start-delim end-delim t t)) + (label-and-file (nth 0 label-start-end)) + (start-pos (nth 1 label-start-end)) + (end-pos (nth 2 label-start-end)) + lbl but-key lbl-key key-file) + (when label-and-file + (setq label-and-file (parse-label-and-file label-and-file) + lbl (nth 0 label-and-file) + but-key (hbut:label-to-key lbl) + key-file (nth 1 label-and-file) + lbl-key (when but-key (concat label-prefix but-key))) + (ibut:label-set lbl start-pos end-pos) + (hact link-actype but-key key-file)))) + +(defun parse-label-and-file (label-and-file) + "Parse a colon-separated string of button label and source file path into a list of label and file." + ;; Can't use split-string here because file path may contain colons; + ;; we want to split only on the first colon. + (let ((i 0) + (len (length label-and-file)) + label + file) + (while (< i len) + (when (= ?: (aref label-and-file i)) + (when (zerop i) + (error "(parse-label-and-file): Missing label: '%s'" label-and-file)) + (setq label (string-trim (substring label-and-file 0 i)) + file (string-trim (substring label-and-file (1+ i)))) + (when (string-empty-p label) (setq label nil)) + (when (string-empty-p file) (setq file nil)) + (setq i len)) + (setq i (1+ i))) + (unless (or label (string-empty-p label-and-file)) + (setq label label-and-file)) + (delq nil (list label file)))) (defconst elink:start "<elink:" "String matching the start of a link to a Hyperbole explicit button.") @@ -709,15 +747,10 @@ Requires the Emacs builtin Tramp library for ftp file retrievals." "At point, activates a link to an explicit button. 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)) - (ebut-key (nth 0 label-key-start-end)) - (lbl-key (and ebut-key (concat "elink_" ebut-key))) - (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 ebut-key)))) +Recognizes the format '<elink:' button_label [':' button_file_path] '>', +where : button_file_path is given only when the link is to another file, +e.g. <elink: project-list: ~/projs>." + (hlink 'link-to-ebut "elink_" elink:start elink:end)) (defconst glink:start "<glink:" "String matching the start of a link to a Hyperbole global button.") @@ -728,15 +761,9 @@ Recognizes the format '<elink:' <button label> '>', e.g. <elink: project-list>." "At point, activates a link to a global button. 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)) - (gbut-key (nth 0 label-key-start-end)) - (lbl-key (and gbut-key (concat "glink_" gbut-key))) - (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 gbut-key)))) +Recognizes the format '<glink:' button_label '>', +e.g. <glink: open todos>." + (hlink 'link-to-gbut "glink_" glink:start glink:end)) (defconst ilink:start "<ilink:" "String matching the start of a link to a Hyperbole implicit button.") @@ -747,15 +774,10 @@ Recognizes the format '<glink:' <button label> '>', e.g. <glink: open todos>." "At point, activates a link to a labeled implicit button. 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)) - (ibut-key (nth 0 label-key-start-end)) - (lbl-key (and ibut-key (concat "ilink_" ibut-key))) - (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 ibut-key)))) +Recognizes the format '<ilink:' button_label [':' button_file_path] '>', +where button_file_path is given only when the link is to another file, +e.g. <ilink: my series of keys: ${hyperb:dir}/HYPB>." + (hlink 'link-to-ibut "ilink_" ilink:start ilink:end)) ;;; ======================================================================== ;;; Jumps to source line associated with ipython, ripgrep, grep or