emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/hyperbole 962be77 2/3: Action Key chooses a path to fin


From: ELPA Syncer
Subject: [elpa] externals/hyperbole 962be77 2/3: Action Key chooses a path to find from PATH-type variables
Date: Sun, 18 Apr 2021 02:57:09 -0400 (EDT)

branch: externals/hyperbole
commit 962be77a67e11fa6f28e139ed0fefd5285c6e077
Author: Bob Weiner <rsw@gnu.org>
Commit: Bob Weiner <rsw@gnu.org>

    Action Key chooses a path to find from PATH-type variables
    
    Plus a bunch of bug fixes.
---
 Changes       | 30 ++++++++++++++++++++++++++----
 hibtypes.el   | 19 +++++++++++++++----
 hmouse-drv.el | 24 ++++++++++++------------
 hmouse-tag.el | 38 +++++++++++++++++++++-----------------
 hpath.el      | 36 +++++++++++++++++++++++++++++++-----
 5 files changed, 105 insertions(+), 42 deletions(-)

diff --git a/Changes b/Changes
index d967f2a..a066e7f 100644
--- a/Changes
+++ b/Changes
@@ -1,7 +1,29 @@
+2021-04-18  Bob Weiner  <rsw@gnu.org>
+
+* hpath.el (hpath:is-path-variable-p): Add to test if a string is a 
path-related variable.
+           (hpath:choose-from-path-variable):
+  hibtypes.el (pathname): Use this new function.
+
+* hibtypes.el (require 'hversion): Add this since added calls to  hyperb:* 
into this file.
+
 2021-04-17  Bob Weiner  <rsw@gnu.org>
 
-* hpath.el (hpath:expand): Fix locate-library call to add suffixes and thereby
-    improperly match non-Lisp files with generic names to Lisp library files.
+* hpath.el (hpath:path-variable-regexp, hpath:choose-from-path-variable): Add.
+  hibtypes.el (pathname): Add Action Key activation of *PATH* environment 
variables and
+    completion-based selection of the desired choice which Hyperbole then 
displays.
+
+* hmouse-tag.el (smart-lisp-at-tag-p): Ignore referenced environment variables 
(include $).
+
+* hpath.el (hpath:delimited-possible-path): Ignore space delimited / or \\
+    which look like root directories but are not.
+
+* hibtypes.el (rfc-toc): Make buffer-name match tighter so does not match to
+    *rfc toc* buffers.
+
+* hibtypes.el (pathname):
+  hpath.el (hpath:expand): Fix locate-library calls to not add suffixes and 
thereby
+    ignore non-Lisp files with generic names that match Lisp library names when
+    a suffix is added.
 
 * hui-mouse.el (hkey-alist): Raised priorty of occur modes so don't trigger
     tag finding when on an occurrence line.
@@ -24,7 +46,7 @@
     path variables.
            (hpath:call): Fix yesterday's handling of anchor only
     references like "#Smart Keys" from DEMO file.
-           (hpath:path-variable-regexp): For Windows, replace : should be ;.
+           (hpath:path-variable-value-regexp): For Windows, replace : should 
be ;.
           (hpath:is-p): Prevent from matching to PATH-type strings with at
     least 4 entries; fixes Action Key on Windows path within PATH variable.
 
@@ -39,7 +61,7 @@
     pathnames.
            (hpath:expand): For compressed Elisp libraries, add any
     found compressed suffix to the path.
-           (hpath:path-variable-regexp): Add.
+           (hpath:path-variable-value-regexp): Add.
           (hpath:at-p): Use above variable and detect paths within PATH
     variables so Action Key can display them.
            (hpath:is-p): Fix to return nil if path ends up as an empty string.
diff --git a/hibtypes.el b/hibtypes.el
index 43a26ee..13b28e1 100644
--- a/hibtypes.el
+++ b/hibtypes.el
@@ -33,6 +33,7 @@
 ;;; Other required Elisp libraries
 ;;; ************************************************************************
 
+(eval-when-compile (require 'hversion))
 (require 'subr-x) ;; For string-trim
 (require 'hactypes)
 
@@ -207,13 +208,22 @@ display options."
                  (apply #'ibut:label-set path (hpath:start-end path))
                  (hact 'link-to-file path))
         ;;
-        ;; Match to Emacs Lisp and Info files without any directory component.
+        ;; Match PATH-related Environment and Lisp variable names and
+       ;; to Emacs Lisp and Info files without any directory component.
         (when (setq path (hpath:delimited-possible-path))
-          (cond ((string-match "\\`[^\\\\/~]+\\.el[cn]?\\(\\.gz\\)?\\'" path)
+          (cond ((and (string-match hpath:path-variable-regexp path)
+                     (setq path (match-string 1 path))
+                     (hpath:is-path-variable-p path))
+                (setq path (if (or assist-flag (hyperb:stack-frame 
'(hkey-help)))
+                               path
+                             (hpath:choose-from-path-variable path "Display")))
+                (unless (or (null path) (string-empty-p path))
+                  (hact 'link-to-file path)))
+               ((string-match "\\`[^\\\\/~]+\\.el[cn]?\\(\\.gz\\)?\\'" path)
                  (apply #'ibut:label-set path (hpath:start-end path))
                  (if (string-match hpath:prefix-regexp path)
                      (hact 'hpath:find path)
-                   (setq full-path (locate-library path))
+                   (setq full-path (locate-library path t))
                    (if full-path
                        (hact 'link-to-file full-path)
                      (hact 'error "(pathname): \"%s\" not found in `load-path'"
@@ -391,7 +401,8 @@ Each line in the summary may be selected to jump to a 
section."
   (let ((case-fold-search t)
         (toc)
         (opoint (point)))
-    (if (and (string-match "rfc" (buffer-name))
+    (if (and (string-match "\\`rfc[-_]?[0-9]" (buffer-name))
+            (not (string-match "toc" (buffer-name)))
              (goto-char (point-min))
              (progn (setq toc (search-forward "Table of Contents" nil t))
                     (re-search-forward "^[ \t]*1.0?[ \t]+[^ \t\n\r]" nil t
diff --git a/hmouse-drv.el b/hmouse-drv.el
index 82715b8..f56b8ee 100644
--- a/hmouse-drv.el
+++ b/hmouse-drv.el
@@ -1388,23 +1388,14 @@ and returns nil."
        t)))
 
 ;; "hsettings.el" contains documentation for this variable.
-(or (boundp 'smart-scroll-proportional)
-    (defvar smart-scroll-proportional t
-      "*Non-nil means Smart Keys should scroll relative to current line when 
pressed at the end of a line.
+(unless (boundp 'smart-scroll-proportional)
+  (defvar smart-scroll-proportional t
+    "*Non-nil means Smart Keys should scroll relative to current line when 
pressed at the end of a line.
 Action Key moves current line to top of window.  Assist Key moves current
 line to bottom of window.  Repeated presses then scroll up or down a
 windowful.  Nil value instead ignores current line and always scrolls up or
 down a windowful."))
 
-;; The smart keys scroll buffers when pressed at the end of lines.
-;; These next two functions do the scrolling and keep point at the end
-;; of line to simplify repeated scrolls when using keyboard smart keys.
-;;
-;; These functions may also be used to test whether the scroll action would
-;; be successful: no action is taken if it would fail (because the beginning
-;; or end of a buffer is already showing) and nil is returned.
-;; t is returned whenever scrolling is performed.
-
 (defun hmouse-function (func assist-flag set-point-arg-list)
   "Execute FUNC for Action Key (Assist Key with ASSIST-FLAG non-nil) and set 
point from SET-POINT-ARG-LIST.
 FUNC may be nil in which case no function is called.
@@ -1435,6 +1426,15 @@ is not bound to a valid function."
            action-mouse-key-prefix-arg nil))
     t))
 
+;; The smart keys scroll buffers when pressed at the end of lines.
+;; These next two functions do the scrolling and keep point at the end
+;; of line to simplify repeated scrolls when using keyboard smart keys.
+;;
+;; These functions may also be used to test whether the scroll action would
+;; be successful: no action is taken if it would fail (because the beginning
+;; or end of a buffer is already showing) and nil is returned.
+;; t is returned whenever scrolling is performed.
+
 (defun smart-scroll-down ()
   "Scroll down according to value of smart-scroll-proportional.
 If smart-scroll-proportional is nil or if point is on the bottom window line,
diff --git a/hmouse-tag.el b/hmouse-tag.el
index b073275..f4930a0 100644
--- a/hmouse-tag.el
+++ b/hmouse-tag.el
@@ -664,25 +664,29 @@ Return nil when point is on the first line of a non-alias 
Lisp definition."
   (unless (smart-lisp-at-definition-p)
     (save-excursion
       (skip-chars-backward smart-lisp-identifier-chars)
-      (when (and (looking-at smart-lisp-identifier)
-                ;; Ignore any punctuation matches.
-                (save-match-data
-                  (not (string-match "\\`[-<>*]+\\'" (match-string 0)))))
-       ;; Ignore any leading '<' character from action buttons or
-       ;; other links, i.e. only when followed by an alphabetic character.
-       (when (and (eq (following-char) ?\<) (eq ?w (char-syntax (1+ (point)))))
-         (goto-char (1+ (point))))
-       (if no-flash
+      ;; Ignore environment variables: $PATH, ${PATH}, $(PATH), {$PATH}, 
($PATH)
+      (unless (save-excursion
+               (skip-chars-backward "[${(]")
+               (looking-at "\\$[{(]\\|[{]\\$]"))
+       (when (and (looking-at smart-lisp-identifier)
+                  ;; Ignore any punctuation matches.
+                  (save-match-data
+                    (not (string-match "\\`[-<>*]+\\'" (match-string 0)))))
+         ;; Ignore any leading '<' character from action buttons or
+         ;; other links, i.e. only when followed by an alphabetic character.
+         (when (and (eq (following-char) ?\<) (eq ?w (char-syntax (1+ 
(point)))))
+           (goto-char (1+ (point))))
+         (if no-flash
+             (if (eq (char-after (1- (match-end 0))) ?:)
+                 (buffer-substring-no-properties (point) (1- (match-end 0)))
+               (buffer-substring-no-properties (point) (match-end 0)))
            (if (eq (char-after (1- (match-end 0))) ?:)
-               (buffer-substring-no-properties (point) (1- (match-end 0)))
-             (buffer-substring-no-properties (point) (match-end 0)))
-         (if (eq (char-after (1- (match-end 0))) ?:)
+               (smart-flash-tag
+                (buffer-substring-no-properties (point) (1- (match-end 0)))
+                (point) (1- (match-end 0)))
              (smart-flash-tag
-              (buffer-substring-no-properties (point) (1- (match-end 0)))
-              (point) (1- (match-end 0)))
-           (smart-flash-tag
-            (buffer-substring-no-properties (point) (match-end 0))
-            (point) (match-end 0))))))))
+              (buffer-substring-no-properties (point) (match-end 0))
+              (point) (match-end 0)))))))))
 
 ;;;###autoload
 (defun smart-lisp-mode-p ()
diff --git a/hpath.el b/hpath.el
index 592d001..d9a11f9 100644
--- a/hpath.el
+++ b/hpath.el
@@ -57,7 +57,11 @@ Group 1 is the line number.  Group 3 is the column number.")
   "Regexp that matches a markup filename followed by a hash (#) and an 
optional in-file anchor name.
 # is group 2.  Group 3 is the anchor name.")
 
-(defvar hpath:path-variable-regexp
+(defvar hpath:path-variable-regexp 
"\\`\\$?[{(]?\\([-_A-Z]*path[-_A-Z]*\\)[)}]?\\'"
+  "Regexp that matches exactly to a standalone path variable name reference.
+Group 1 is the variable name.")
+
+(defvar hpath:path-variable-value-regexp
  (concat 
"\\`\\.?:[^:;]+:[^:;]+:\\|:\\.?:\\|:[^:;]+:[^:;]+:\\|:[^:;]+:[^:;]+:\\.?\\'"
         "\\|"
         
"\\`\\.?;[^;]+;[^;]+;\\|;\\.?;\\|;[^;]+;[^;]+;\\|;[^;]+;[^;]+;\\|;[^;]+;[^;]+;\\.?\\'")
@@ -798,7 +802,7 @@ paths are allowed.  Absolute pathnames must begin with a 
`/' or `~'."
          subpath)
      (when (and path (not non-exist) (string-match hpath:prefix-regexp path))
        (setq non-exist t))
-     (if (and path (string-match hpath:path-variable-regexp path))
+     (if (and path (string-match hpath:path-variable-value-regexp path))
         ;; With point inside a path variable, return the path that point is on 
or to the right of.
         (or (and (setq subpath (hargs:delimited "[:\"\']" "[:\"\']" t t nil 
"[\t\n\r\f]\\|[;:] \\| [;:]"))
                  (not (string-match "[:;]" subpath))
@@ -865,6 +869,27 @@ Make any path within a file buffer absolute before 
returning. "
                 (setq path (concat mode-prefix default-directory path))))
              (t path))))))
 
+(defun hpath:is-path-variable-p (path-var)
+  "Return the value of a colon or semicolon-delimited set in PATH-VAR or nil 
if not a match."
+  (when (stringp path-var)
+    (or (getenv path-var)
+        (let ((sym (intern-soft path-var)))
+         (and sym (boundp sym) (stringp (symbol-value sym)) (symbol-value 
sym))))))
+
+(defun hpath:choose-from-path-variable (path-var &optional action-str)
+  "Interactively choose and return a path from the colon or 
semicolon-delimited set in PATH-VAR."
+  (let (path-value
+       paths)
+    (when (setq path-value (hpath:is-path-variable-p path-var)
+               paths (and path-value
+                          (split-string path-value (if (string-match ";" 
path-value) ";" ":") nil "\\s-")))
+      (setq paths (sort (mapcar (lambda (path) (if (string-empty-p path) "." 
path)) paths) #'string-lessp))
+      (kbd-key:key-series-to-events "?")
+      (completing-read (format "%s path from ${%s}: "
+                              (if (stringp action-str) action-str "Choose")
+                              path-var)
+                      paths nil t))))
+
 (defun hpath:delimited-possible-path (&optional non-exist include-positions)
   "Return delimited possible path or non-delimited remote path at point, if 
any.
 No validity checking is done on the possible path.  Delimiters may be:
@@ -894,8 +919,9 @@ end-pos) or nil."
                 (p (car triplet))
                 (punc (char-syntax ?.)))
            ;; May have matched to a string with an embedded double
-           ;; quote; if so, don't consider it a path.
-           (when (and (stringp p) (not (string-match "\"" p)) 
+           ;; quote; if so, don't consider it a path.  Also ignore
+           ;; whitespace delimited root dirs, e.g. " / ".
+           (when (and (stringp p) (not (string-match "\"\\|\\`[/\\]+\\'" p))
                       (delq nil (mapcar (lambda (c) (/= punc (char-syntax c))) 
p)))
              (if include-positions
                  triplet
@@ -1268,7 +1294,7 @@ stripped, link anchors at the end following a # or , 
character
 are temporarily stripped, and path variables are expanded with
 `hpath:substitute-value'.  This normalized path form is what is
 returned for PATH."
-  (when (and (stringp path) (not (string-match hpath:path-variable-regexp 
path)))
+  (when (and (stringp path) (not (string-match 
hpath:path-variable-value-regexp path)))
     (setq path (hpath:call
                (lambda (path)
                  (let (modifier



reply via email to

[Prev in Thread] Current Thread [Next in Thread]