-
Notifications
You must be signed in to change notification settings - Fork 11
/
hpath.el
2740 lines (2531 loc) · 116 KB
/
hpath.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; hpath.el --- GNU Hyperbole support routines for handling POSIX and MSWindows paths -*- lexical-binding: t; -*-
;;
;; Author: Bob Weiner
;;
;; Orig-Date: 1-Nov-91 at 00:44:23
;; Last-Mod: 18-Nov-24 at 20:16:58 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 1991-2024 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.
;;; Commentary:
;;; Code:
;;; ************************************************************************
;;; Other required Elisp libraries
;;; ************************************************************************
(require 'cl-lib)
(require 'hact)
(require 'seq) ;; For seq-find
(require 'subr-x) ;; For string-trim
(require 'hversion) ;; for (hyperb:window-system) definition
(require 'hui-select) ;; for `hui-select-markup-modes'
(require 'tramp)
(unless (fboundp 'br-in-browser)
;; Then the OO-Browser is not loaded, so we can never be within the
;; browser. Define this as a dummy function that always returns nil
;; until the OO-Browser is ever loaded.
(defun br-in-browser ()
"Always returns nil since the OO-Browser is not loaded."
nil))
;;; ************************************************************************
;;; Public Variables
;;; ************************************************************************
(defcustom hpath:auto-completing-read-modes '(helm-mode ivy-mode selectrum-mode)
"*List of boolean mode variables whose modes automatically list completions.
These are modes where completions are listed without the need for
pressing the ? key."
:type '(repeat variable)
:group 'hyperbole-commands)
(defvar hpath:auto-variable-alist
'(("\\.el[cn]?\\'" . load-path)
("\\.org\\'" . org-directory)
("\\.py\\'" . "PYTHONPATH"))
"Alist of filename patterns and related variables to prepend to resolve them.
Each element looks like FILENAME-REGEXP . LISP-VARIABLE-OR-ENV-VARIABLE-STR.
The VARIABLE value may be: a directory path, a list of directory paths
or a colon or semicolon delimited string of directory paths.")
(defcustom hpath:find-file-urls-mode nil
"Set to t to enable use of ftp and http urls in file finding commands.
Requires that a remote file access library is available.
Default is nil since this can slow down normal file finding."
:type 'boolean
:initialize #'custom-initialize-default
:set (lambda (_symbol _value) (call-interactively #'hpath:find-file-urls-mode))
:group 'hyperbole-buttons)
(defconst hpath:line-and-column-regexp
":L?\\([-+]?[0-9]+\\)\\(:C?\\([-+]?[0-9]+\\)\\)?\\s-*\\'"
"Regexp matching a trailing line number and optional column number.
Path, line and column numbers are colon separated. Group 1 is the
1-based line number. Group 3 is the 0-based column number.")
(defconst hpath:instance-line-column-regexp
":I\\([-+]?[0-9]+\\)\\(:L?\\([-+]?[0-9]+\\)\\)?\\(:C?\\([-+]?[0-9]+\\)\\)?\\s-*\\'"
"Regexp matching a trailing instance, optional line, and column number.
Path, instance, line, and column numbers are colon separated. Group 1
is the instance/occurrence number when searching from the buffer start.
Group 3 is the 1-based line number. Group 5 is the 0-based column number.")
(defconst hpath:markup-link-anchor-regexp
"\\`\\(#?[^#+]*[^#+.]\\)?\\(#\\)\\([^\]\[#+^{}<>\"`'\\\n\t\f\r]*\\)"
"Regexp matching a filename followed by a hash (#) and an optional anchor name.
The anchor is an in-file reference. # is group 2. Group 3 is the anchor
name.")
(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
(let* ((posix-separators ":;")
(windows-separators ";")
(reserved-chars "<>:\"|?*")
(exclude-space "\t\n\r\f")
(control-chars "[:cntrl:]")
;; Posix char set to exclude from paths
(nope (concat "\[^" posix-separators reserved-chars exclude-space control-chars "\]+"))
;; Windows char set to exclude from paths
(nowin (concat "\[^" windows-separators reserved-chars exclude-space control-chars "\]+")))
(concat "\\`\\.?:" nope ":" nope ":\\|:\\.?:" nope ":\\|:" nope ":" nope ":\\|:" nope ":" nope ":\\.?\\'"
"\\|"
"\\`\\.?;" nowin ";" nowin ";\\|;\\.?;\\|;" nowin ";" nowin ";\\|;" nowin ";" nowin ";\\|;" nowin ";" nowin ";\\.?\\'"))
;; A zero-length (null) directory name in the value of PATH indicates the current directory.
;; A null directory name may appear as two adjacent colons, or as an initial or trailing colon.
"Regexp that heuristically matches to Posix or Windows path variable values.
Posix has colon-separated and Windows has semicolon-separated
path variable values.")
(defconst hpath:section-line-and-column-regexp
"\\([^ \t\n\r\f:][^\t\n\r\f:]+\\(:[^0-9\t\n\r\f]*\\)*\\):L?\\([0-9]+\\)\\(:C?\\([0-9]+\\)\\)?$"
"Regexp that matches to a path with optional #section and :line:col.
Grouping 1 is path, grouping 3 is line number, grouping 4 is column
number. Allow for \\='c:' single letter drive prefixes on MSWindows and
Elisp vars with colons in them. Line and column can include a leading
and optional character, L for line and C for column.")
(defconst hpath:variable-regexp "\\$@?\{\\([^\}]+\\)@?\}"
"Regexp matching variable names that Hyperbole resolves within pathnames.
The format is ${variable}. Match grouping 1 is the name of the variable.")
;;; ************************************************************************
;;; Public Declarations
;;; ************************************************************************
(declare-function br-quit "ext:br")
(declare-function br-in-browser "ext:br")
(declare-function br-to-view-window "ext:br")
(declare-function mm-mailcap-command "mm-decode")
(declare-function hypb:decode-url "hypb")
(declare-function hattr:get "hbut")
(declare-function kbd-key:key-series-to-events "hib-kbd")
(declare-function hbut:label-to-key "hbut")
(declare-function hbut:key-to-label "hbut")
(declare-function hargs:delimited "hargs")
(declare-function hypb:object-p "hypb")
(declare-function Info-find-node "info")
(declare-function kcell-view:indent "kcell-view")
(declare-function klink:act "klink")
;;; ************************************************************************
;;; MS WINDOWS PATH CONVERSIONS
;;; ************************************************************************
;; This section adds automatic recognition of MSWindows implicit path
;; links and converts disk drive and path separators to whatever
;; format is needed by the underlying OS upon which Emacs is one,
;; notably either for POSIX or MSWindows (with no POSIX layer).
;; Especially useful when running Emacs under Windows Subsystem for
;; Linux (WSL) where the system-type variable is gnu/linux but
;; MSWindows is underneath so the user likely has many Windows
;; formatted links.
;; See "https://docs.microsoft.com/en-us/dotnet/standard/io/file-path-formats"
;; and "https://docs.microsoft.com/en-us/windows/wsl/interop" for
;; Windows path specifications and use under WSL.
(defvar hpath:posix-mount-points-regexp
"^\\(Filesystem\\|rootfs\\|none\\) "
"Regexp of \\='mount' output lines that are not mount points of MSWindows paths.")
(defvar hpath:mswindows-mount-prefix
(cond ((eq system-type 'cygwin)
"/cygdrive/")
(hyperb:microsoft-os-p
"")
(t ;; POSIX
"/mnt/"))
"Path prefix to add when converting MSWindows drive paths to POSIX-style.
Must include a trailing directory separator or be nil.")
(defconst hpath:mswindows-drive-regexp (format "\\`\\(%s\\)?[\\/]?\\([a-zA-Z]\\)[:\\/]"
hpath:mswindows-mount-prefix)
"Regular expression matching an MSWindows drive letter.
Matches at the beginning of a path string. Grouping 2 is the
actual letter of the drive. If the value of
`hpath:mswindows-mount-prefix' changes, then re-initialize this
constant.")
(defconst hpath:mswindows-path-regexp "\\`.*\\.*[a-zA-Z0-9_.]"
"Regexp matching the start of an MSWindows path without a drive letter.
Path contains directory separators.")
;;;###autoload
(defvar hpath:posix-mount-point-to-mswindows-alist nil
"Automatically set alist of (posix-mount-point . window-path-prefix) elements.
Used to expand posix mount points to Windows UNC paths during
posix-to-mswindows conversion.")
;;;###autoload
(defun hpath:mswindows-to-posix (path)
"Convert a MSWindows PATH to a Posix-style path or return the path unchanged.
If path begins with an MSWindows drive letter, prefix the
converted path with the value of `hpath:mswindows-mount-prefix'."
(interactive "sMSWindows path to convert to POSIX: ")
(when (and (stringp path) (not (equal path "\\\\")))
(setq path (hpath:mswindows-to-posix-separators path))
(when (string-match hpath:mswindows-drive-regexp path)
(when (string-match hpath:mswindows-drive-regexp path)
(let* ((drive-prefix (downcase (match-string 2 path)))
(rest-of-path (substring path (match-end 0)))
(absolute-p (and (not (string-empty-p rest-of-path))
(= (aref rest-of-path 0) ?/))))
;; Convert MSWindows disk drive paths to POSIX-style with a mount prefix.
(setq path (concat hpath:mswindows-mount-prefix drive-prefix
(cond (hyperb:microsoft-os-p ":")
(absolute-p "")
(t "/"))
rest-of-path))))))
path)
(defun hpath:mswindows-to-posix-separators (path)
"Replace backslashes with forward slashes and abbreviate the PATH if possible.
Path must be a string or an error will be triggered. See
`abbreviate-file-name' for how path abbreviation is handled."
(setq path (replace-regexp-in-string "\\\\" "/" path)
;; Downcase any host and domain for mount-point matching
path (if (string-match "\\`//[^/:]+" path)
(concat (downcase (match-string 0 path))
(substring path (match-end 0)))
path)
path (hpath:abbreviate-file-name path)
path (replace-regexp-in-string (regexp-quote "\\`") "" path)
path (replace-regexp-in-string (regexp-quote "\\>") "" path)))
;;;###autoload
(defun hpath:posix-to-mswindows (path)
"Convert a Posix-style PATH to an MSWindows path or return the path unchanged.
If path begins with an optional mount prefix,
`hpath:mswindows-mount-prefix', followed by an MSWindows drive
letter, remove the mount prefix."
(interactive "sPOSIX path to convert to MSWindows: ")
(when (stringp path)
(setq path (hpath:posix-to-mswindows-separators path))
;; Remove any POSIX mount prefix preceding an MSWindows path.
(if (eq 0 (string-match hpath:mswindows-mount-prefix path))
(setq path (substring path (match-end 0))))
(when (string-match hpath:mswindows-drive-regexp path)
(when (string-match hpath:mswindows-drive-regexp path)
(let* ((drive-prefix (downcase (match-string 2 path)))
(rest-of-path (substring path (match-end 0)))
(absolute-p (= (aref path (1- (match-end 0))) ?\\)))
;; Convert formerly Posix-style Windows disk drive paths to MSWindows-style.
(setq path (concat drive-prefix ":"
(if (or (not absolute-p)
(string-match "\\`[~/]" rest-of-path))
""
"\\")
rest-of-path))))))
path)
(defun hpath:posix-to-mswindows-separators (path)
"Replace forward slashes with backslashes and abbreviate the PATH if possible.
Path must be a string or an error will be triggered. See
`abbreviate-file-name' for how path abbreviation is handled."
(let ((directory-abbrev-alist hpath:posix-mount-point-to-mswindows-alist))
(replace-regexp-in-string "/" "\\\\" (hpath:abbreviate-file-name path))))
(defun hpath:posix-path-p (path)
"Return non-nil if PATH looks like a Posix path."
(and (stringp path) (string-match "/" path)))
;;;###autoload
(defun hpath:substitute-posix-or-mswindows-at-point ()
"If point is in a Posix or MSWindows path, change the path to the other type."
(interactive "*")
(barf-if-buffer-read-only)
(let* ((opoint (point))
(str-and-positions (hpath:delimited-possible-path t t))
(path (car str-and-positions))
(start (nth 1 str-and-positions))
(end (nth 2 str-and-positions)))
(when path
(if (hpath:posix-path-p path)
(setq path (hpath:posix-to-mswindows path))
(setq path (hpath:mswindows-to-posix path)))
(delete-region start end)
(insert path)
(goto-char (min opoint (point-max))))))
;;;###autoload
(defun hpath:substitute-posix-or-mswindows (path)
"Change a recognizable Posix or MSWindows PATH to the other type of path."
(when (stringp path)
(if (hpath:posix-path-p path)
(hpath:posix-to-mswindows path)
(hpath:mswindows-to-posix path))))
;;;###autoload
(defun hpath:cache-mswindows-mount-points ()
"Cache valid MSWindows mounts when under a non-MSWindows OS, e.g. WSL.
Mount points are cached in `directory-abbrev-alist'.
Call this function manually if mount points change after Hyperbole is loaded."
(interactive)
(when (not hyperb:microsoft-os-p)
(let (mount-points-to-add)
;; Convert plist to alist for sorting.
(hypb:map-plist (lambda (path mount-point)
(when (string-match "\\`\\([a-zA-Z]\\):\\'" path)
(setq path (concat "/" (match-string 1 path))))
;; Drive letter must be downcased
;; in order to work when converted back to Posix.
;; Assume all mounted Windows paths are
;; lowercase for now.
(setq path (downcase path))
(push (cons (downcase path) mount-point)
mount-points-to-add)
;; If a network share with a domain
;; name, also add an entry WITHOUT the
;; domain name to the mount points
;; table since Windows paths often omit
;; the domain.
(when (string-match "\\`\\([\\/][\\/][^.\\/]+\\)\\([^\\/]+\\)" path)
(push (cons (concat (match-string 1 path)
(substring path (match-end 0)))
mount-point)
mount-points-to-add)))
;; Return a plist of MSWindows path-mounted mount-point pairs.
;; Next call will raise an error if default-directory is set to
;; a URL, e.g. in RFC buffers; just ignore it and return nil in
;; such a case.
(ignore-errors
(split-string (shell-command-to-string (format "df -a -t drvfs 2> /dev/null | sort | uniq | grep -v '%s' | sed -e 's+ .*[-%%] /+ /+g'" hpath:posix-mount-points-regexp)))))
;; Sort alist of (path-mounted . mount-point) elements from shortest
;; to longest path so that the longest path is selected first within
;; 'directory-abbrev-alist' (elements are added in reverse order).
(setq mount-points-to-add
(sort mount-points-to-add
(lambda (cons1 cons2) (<= (length (car cons1)) (length (car cons2))))))
(let (path
mount-point)
(mapc (lambda (path-and-mount-point)
(setq path (car path-and-mount-point)
mount-point (cdr path-and-mount-point))
;; Don't abbreviate /mnt or /cygdrive to /, skip this entry.
(unless (equal mount-point "/")
(add-to-list 'directory-abbrev-alist (cons (format "\\`%s\\>" (regexp-quote path))
mount-point))))
mount-points-to-add))
;; Save the reverse of each mount-points-to-add so
;; can expand paths when going from posix-to-mswindows.
(setq hpath:posix-mount-point-to-mswindows-alist
(mapcar (lambda (elt) (cons (concat "\\`" (cdr elt) "\\>")
(car elt))) mount-points-to-add))
mount-points-to-add)))
;;; ************************************************************************
;;; FILE VIEWER COMMAND SETTINGS
;;; ************************************************************************
(defcustom hpath:external-open-office-suffixes "doc[mx]?\\|od[st]\\|ppsx?\\|ppt[mx]?\\|v[dst][s]?[tx]\\|vsd[x]?\\|xls[mx]?"
"*Regexp of Open Office document suffix alternatives.
These are to be display externally with the Action Key
Do not include an initial period or enclosing grouping parentheses;
these will be added automatically.
See http://www.openwith.org/programs/openoffice for a full list of
possible suffixes."
:type 'string
:group 'hyperbole-commands)
(defcustom hpath:external-file-suffixes "e?ps\\|dvi\\|pdf\\|ps\\.g?[zZ]\\|gif\\|tiff?\\|xpm\\|xbm\\|xwd\\|pm\\|pbm\\|jpe?g\\|ra?s\\|xcf"
"*Non-operating system dependent regexp of file suffixes to open outside Emacs.
These are opened with the Action Key when not handled by
`hpath:native-image-suffixes'. Do not include an initial period
or enclosing grouping parentheses; these will be added
automatically."
:type 'string
:group 'hyperbole-commands)
(defcustom hpath:external-display-alist-macos (list (cons (format "\\.\\(%s\\|%s\\|app\\|adaptor\\|bshlf\\|clr\\|concur\\|create\\|diagram\\|dp\\|frame\\|locus\\|Mesa\\|nib\\|project\\|rtf\\|sense\\|tree\\)$"
hpath:external-open-office-suffixes
hpath:external-file-suffixes)
"open"))
"*An alist of (FILENAME-REGEXP . DISPLAY-PROGRAM-STRING-OR-LIST) for the macOS.
See the function `hpath:get-external-display-alist' for detailed
format documentation."
:type '(alist :key-type regexp :value-type string)
:group 'hyperbole-commands)
(defcustom hpath:external-display-alist-mswindows (list (cons (format "\\.\\(%s\\)$" hpath:external-open-office-suffixes)
"openoffice.exe")
(cons (format "\\.\\(%s\\|vba\\)$" hpath:external-file-suffixes)
"/c/Windows/System32/cmd.exe //c start \"${@//&/^&}\""))
"*An alist of (FILENAME-REGEXP . DISPLAY-PROGRAM-STRING-OR-LIST) for MS Windows.
See the function `hpath:get-external-display-alist' for detailed
format documentation."
:type '(alist :key-type regexp :value-type string)
:group 'hyperbole-commands)
;; Old X Window System configuration prior to use of 'xdg-open'.
;; (defvar hpath:external-display-alist-x (list '("\\.e?ps$" . "ghostview")
;; '("\\.dvi$" . "xdvi")
;; (cons (format "\\.\\(%s\\)$" hpath:external-open-office-suffixes) "openoffice")
;; '("\\.pdf$" . ("xpdf" "acroread"))
;; '("\\.ps\\.g?[zZ]$" . "zcat %s | ghostview -")
;; '("\\.\\(gif\\|tiff?\\|xpm\\|xbm\\|xwd\\|pm\\|pbm\\|jpe?g\\)" . "xv")
;; '("\\.ra?s$" . "snapshot -l"))
(defcustom hpath:external-display-alist-x (list (cons (format "\\.\\(%s\\|%s\\)$"
hpath:external-open-office-suffixes
hpath:external-file-suffixes)
"setsid -w xdg-open"))
"*An alist of (FILENAME-REGEXP . DISPLAY-PROGRAM-STRING-OR-LIST) for X.
See the function `hpath:get-external-display-alist' for detailed
format documentation."
:type '(alist :key-type regexp :value-type string)
:group 'hyperbole-commands)
(defvar hpath:info-suffix "\\.info\\(-[0-9]+\\)?\\(\\.gz\\|\\.Z\\|-z\\)?\\'"
"Regexp matching to the end of Info manual file names.")
(defcustom hpath:internal-display-alist
(delq
nil
(list
;; Support internal sound when available.
(if (fboundp 'play-sound-file)
'("\\.\\(au\\|mp3\\|ogg\\|wav\\)$" . play-sound-file))
;; Run the OO-Browser on OOBR or OOBR-FTR Environment files.
'("\\(\\`\\|/\\)\\(OOBR\\|oobr\\).*\\(-FTR\\|-ftr\\)?\\'" . br-env-browse)
;; Display the top node from Info online manuals.
(cons
(concat hpath:info-suffix
"\\|/\\(info\\|INFO\\)/[^.]+$\\|/\\(info-local\\|INFO-LOCAL\\)/[^.]+$")
(lambda (file)
(when (and (string-match hpath:info-suffix file)
(match-beginning 1))
;; Removed numbered trailer to get basic filename.
(setq file (concat (substring-no-properties file 0 (match-beginning 1))
(substring-no-properties file (match-end 1)))))
;; Ensure that Info files with non-absolute directories outside of the
;; `Info-directory-list' are resolved properly, e.g. "man/hyperbole.info".
(unless (file-name-absolute-p file)
(setq file (expand-file-name "man/hyperbole.info")))
(require 'info)
;; Ensure that *info* buffer is displayed in the right place.
(hpath:display-buffer (current-buffer))
(condition-case ()
(Info-find-node file "Top")
(error (if (and file (file-exists-p file))
(progn
(if (get-buffer "*info*")
(kill-buffer "*info*"))
(Info-find-node file "*" nil t))
(error "Invalid file"))))))
'("\\.rdb\\'" . rdb:initialize)))
"*Alist for calling special functions to display file types in Emacs.
The alist consists of (FILENAME-REGEXP . EDIT-FUNCTION) elements.
See also the function (hpath:get-external-display-alist) for
external display program settings."
:type '(alist :key-type regexp :value-type sexp)
:group 'hyperbole-commands)
(defvar hpath:display-buffer-alist
(list
(list 'this-window #'switch-to-buffer)
(list 'other-window (lambda (b)
(if (br-in-browser)
(progn (br-to-view-window)
(switch-to-buffer b))
(switch-to-buffer-other-window b))))
(list 'one-window (lambda (b)
(when (br-in-browser)
(br-quit))
(delete-other-windows)
(switch-to-buffer b)))
(list 'new-frame (lambda (b)
;; Give temporary modes such as isearch a chance to turn off.
(run-hooks 'mouse-leave-buffer-hook)
(select-frame (make-frame (frame-parameters)))
(switch-to-buffer b)))
(list 'other-frame #'hpath:display-buffer-other-frame)
(list 'other-frame-one-window (lambda (b)
(prog1 (hpath:display-buffer-other-frame b)
(delete-other-windows)))))
"*Alist of (DISPLAY-WHERE-SYMBOL DISPLAY-BUFFER-FUNCTION) elements.
This permits fine-grained control of where Hyperbole displays linked to buffers.
The default value of DISPLAY-WHERE-SYMBOL is given by `hpath:display-where'.
Valid DISPLAY-WHERE-SYMBOLs are:
this-window - display in the current window
other-window - display in another window in the current frame
one-window - display in the current window, deleting other
windows
new-frame - display in a new frame
other-frame - display in another, possibly existing, frame
other-frame-one-window - display in another frame, deleting other windows.")
(defvar hpath:display-where 'other-window
"Symbol specifying the default method to use to display Hyperbole link referents.
See documentation of `hpath:display-where-alist' for valid values.
See Info node `(elisp)Choosing Window Options' for where Emacs displays buffers.")
(defvar hpath:display-where-alist
(list
(list 'this-window #'find-file)
(list 'other-window (lambda (f)
(if (br-in-browser)
(progn (br-to-view-window)
(find-file f))
(find-file-other-window f))))
(list 'one-window (lambda (f)
(if (br-in-browser) (br-quit))
(delete-other-windows)
(find-file f)))
(list 'new-frame (lambda (f)
(if (fboundp 'find-file-new-frame)
(find-file-new-frame f)
(hpath:find-other-frame f))))
(list 'other-frame #'hpath:find-other-frame)
(list 'other-frame-one-window (lambda (f)
(prog1 (hpath:find-other-frame f)
(delete-other-windows)))))
"*Alist of (DISPLAY-WHERE-SYMBOL DISPLAY-FILE-FUNCTION) elements.
This permits fine-grained control of where Hyperbole displays
linked to files. The default value of DISPLAY-WHERE-SYMBOL is
given by `hpath:display-where'.
Valid DISPLAY-WHERE-SYMBOLs are:
this-window - display in the current window
other-window - display in another window in the current frame
one-window - display in current window, deleting other windows
new-frame - display in a new frame
other-frame - display in another, possibly existing, frame
other-frame-one-window - display in another frame, deleting other windows.")
(defcustom hpath:native-image-suffixes "\\.\\(xbm\\|xpm\\|xwd\\|png\\|gif\\|jpe?g\\)\\'"
"Regular expression matching file name suffixes of images to display in Emacs.
Used only if the function `image-mode' is defined."
:type 'regexp
:group 'hyperbole-commands)
;;; ************************************************************************
;;; LINK PATH VARIABLE SUBSTITUTION SETTINGS
;;; ************************************************************************
;; The following variable permits sharing of links over wide areas, where
;; links may contain variable references whose values may differ between
;; link creator and link activator.
;;
;; When a link is created, if its path contains a match for any of the
;; variable values in hpath:variables, then the variable's symbol
;; surrounded by ${ } delimiters is substituted for the literal value.
;; Hyperbole then replaces the variable with a matching value when the
;; link is later resolved.
;;
(defcustom hpath:variables
'(hyperb:dir hywiki-directory load-path exec-path Info-directory-list sm-directory)
"*List of Emacs Lisp variable symbols to substitute within matching link paths.
Each variable value, if bound, must be either a pathname or a list of pathnames.
When embedded within a path, the format is ${variable}."
:type '(repeat variable)
:group 'hyperbole-commands)
;;; ************************************************************************
;;; Other public variables
;;; ************************************************************************
(defvar hpath:rfc "https://www.ietf.org/rfc/rfc%s.txt"
"*Url pattern for (hpath:rfc rfc-num) to get the RFC document for `rfc-num'.")
(defcustom hpath:suffixes '(".gz" ".Z")
"*List of filename suffixes to add or remove within hpath calls.
Used by `hpath:exists-p' and `hpath:substitute-dir'."
:type '(repeat string)
:group 'hyperbole-commands)
(defvar hpath:tmp-prefix "/tmp/remote-"
"*Pathname prefix for use with external viewers.
The prefix is attached to remote files when copied locally for viewing.")
;; WWW URL format: [URL[:=]]<protocol>:/[<user>@]<domain>[:<port>][/<path>]
;; or [URL[:=]]<protocol>://[<user>@]<domain>[:<port>][<path>]
;; or URL[:=][<user>@]<domain>[:<port>][<path>] (no protocol specified)
;; Avoid [a-z]:/path patterns since these may be disk paths on OS/2, DOS or
;; Windows.
(defvar hpath:url-regexp "<?\\(URL[:=]\\)?\\(\\([a-zA-Z][a-zA-Z]+\\)://?/?\\([^/:@ \t\n\r\"`'|]+@\\)?\\([^/:@ \t\n\r\"`'|]+\\)\\(\\)\\(:[0-9]+\\)?\\([/~]\\([^\]\[ \t\n\r\"`'|(){}<>]+[^\]\[ \t\n\r\"`'|(){}<>.,?#!*]\\)*\\)?\\)>?"
"Regular expression which matches a Url in a string or buffer.
Its match groupings and their names are:
1 = hpath:url-keyword-grpn = optional `URL:' or `URL=' literal
2 = hpath:url-grpn = the whole URL
3 = hpath:protocol-grpn = access protocol
4 = hpath:username-grpn = optional username
5 = hpath:sitename-grpn = URL site to connect to
6 = unused = for compatibility with hpath:url-regexp2
7 = hpath:portnumber-grpn = optional port number to use
8 = hpath:pathname-grpn = optional pathname to access.")
(defvar hpath:url-hostnames-regexp "\\(www\\|s?ftp\\|telnet\\|news\\|nntp\\)"
"Regexp group of hostnames that contains the Url access protocol to use.")
(defvar hpath:url-regexp2
(concat
"<?\\(URL[:=]\\|[^/@]\\|\\)\\(\\(\\)\\(\\)\\("
hpath:url-hostnames-regexp
"\\.[^/:@ \t\n\r\"`'|]+\\):?\\([0-9]+\\)?\\([/~]\\([^\]\[ \t\n\r\"`'|(){}<>]+[^\]\[ \t\n\r\"`'|(){}<>.,?#!*]\\)*\\)?\\)>?")
"Regular expression which matches a Url in a string or buffer.
Its match groupings and their names are:
1 = hpath:url-keyword-grpn = optional `URL:' or `URL=' literal
2 = hpath:url-grpn = the whole URL
3 = unused = for compatibility with hpath:url-regexp
4 = unused = for compatibility with hpath:url-regexp
5 = hpath:sitename-grpn = URL site to connect to
6 = hpath:hostname-grpn = hostname used to determine the access
protocol, e.g. ftp.domain.com
7 = hpath:portnumber-grpn = optional port number to use
8 = hpath:pathname-grpn = optional pathname to access.")
(defvar hpath:url-regexp3
(concat
"<?\\(URL[:=]\\)\\(\\(\\)\\(\\)"
"\\([a-zA-Z0-9][^/:@ \t\n\r\"`'|]*\\.[^/:@ \t\n\r\"`'|]+\\)"
":?\\([0-9]+\\)?\\([/~]\\([^\]\[ \t\n\r\"`'|(){}<>]+[^\]\[ \t\n\r\"`'|(){}<>.,?#!*]\\)*\\)?\\)>?")
"Regular expression which matches a Url in a string or buffer.
Its match groupings and their names are:
1 = hpath:url-keyword-grpn = required `URL:' or `URL=' literal
2 = hpath:url-grpn = the whole URL
3 = unused = for compatibility with hpath:url-regexp
4 = unused = for compatibility with hpath:url-regexp
5 = hpath:sitename-grpn = URL site to connect to
6 = hpath:hostname-grpn = hostname used to determine the access
protocol, e.g. ftp.domain.com
7 = hpath:portnumber-grpn = optional port number to use
8 = hpath:pathname-grpn = optional pathname to access.")
(defconst hpath:url-keyword-grpn 1
"Optional `URL:' or `URL=' literal.
See doc for `hpath:url-regexp' and `hpath:url-regexp[2,3]'.")
(defconst hpath:url-grpn 2
"The whole URL. See doc for `hpath:url-regexp' and `hpath:url-regexp[2,3]'.")
(defconst hpath:protocol-grpn 3
"Access protocol. See doc for `hpath:url-regexp' and `hpath:url-regexp[2,3]'.")
(defconst hpath:username-grpn 4
"Optional username. See doc for `hpath:url-regexp' and `hpath:url-regexp[2,3]'.")
(defconst hpath:sitename-grpn 5
"URL site to connect to.
See doc for `hpath:url-regexp' and `hpath:url-regexp[2,3]'.")
(defconst hpath:hostname-grpn 6
"Hostname used to determine the access protocol, e.g. sftp.domain.com.
See doc for `hpath:url-regexp' and `hpath:url-regexp[2,3]'.")
(defconst hpath:portnumber-grpn 7
"Optional port number to use.
See doc for `hpath:url-regexp' and `hpath:url-regexp[2,3]'.")
(defconst hpath:pathname-grpn 8
"Optional pathname to access.
See doc for `hpath:url-regexp' and `hpath:url-regexp[2,3]'.")
(defvar hpath:string-url-regexp (concat "\\`" hpath:url-regexp "\\'")
"Regexp that matches to a possibly delimited Url and nothing else.
See the documentation for `hpath:url-regexp' for match groupings to
use with `string-match'.")
(defvar hpath:string-url-regexp2 (concat "\\`" hpath:url-regexp2 "\\'")
"Regexp that matches to a possibly delimited terse Url and nothing else.
See the documentation for `hpath:url-regexp' for match groupings to
use with `string-match'.")
(defvar hpath:string-url-regexp3 (concat "\\`" hpath:url-regexp3 "\\'")
"Regexp that matches to a possibly delimited terse Url and nothing else.
See the documentation for `hpath:url-regexp' for match groupings to
use with `string-match'.")
;;; ************************************************************************
;;; Private variables
;;; ************************************************************************
(defconst hpath:html-anchor-id-pattern "\\(id\\|name\\)=['\"]%s['\"]?"
"Regexp matching an html anchor id definition.
Contains a %s for replacement of a specific anchor id.")
(defconst hpath:markdown-anchor-id-pattern "^[ ]*%s: "
"Regexp matching a Markdown anchor id definition.
Contains a %s for replacement of a specific anchor id.")
(defconst hpath:markdown-section-pattern "^[ \t]*\\(#+\\|\\*+\\)[ \t]+%s\\([\[<\({ \t[:punct:]]*\\)$"
"Regexp matching a Markdown section header.
Contains a %s for replacement of a specific section name.")
(defconst hpath:markdown-suffix-regexp "\\.[mM][dD]"
"Regexp that matches to a Markdown file suffix.")
(defconst hpath:outline-section-pattern "^\\*+[ \t]+%s[ \t]*\\([\[<\({[:punct:]]+\\|$\\)"
"Bol-anchored, no leading spaces regexp matching an Emacs outline section header.
Contains a %s for replacement of a specific section name.")
(defvar hpath:prefix-regexp "\\`[-!&][ ]*"
"Regexp matching command characters which may precede a pathname.
These are used to indicate how to display or execute the pathname.
- means evaluate it as Emacs Lisp;
! means execute it as a shell script
& means run it under the current window system.")
(defvar hpath:remote-regexp
"\\`/[^/:]+:\\|\\`s?ftp[:.]\\|\\`www\\.\\|\\`https?:"
"Regexp matching remote pathnames and urls which invoke remote file handlers.")
(defconst hpath:shell-modes '(sh-mode csh-mode shell-script:mode)
"List of modes for editing shell scripts where # is a comment character.")
(defconst hpath:texinfo-section-pattern "^@node+[ \t]+%s[ \t]*\\(,\\|$\\)"
"Regexp matching a Texinfo section header.
Contains a %s for replacement of a specific section name.")
;;; ************************************************************************
;;; Public functions
;;; ************************************************************************
(defun hpath:abbreviate-file-name (path)
"Return a version of PATH shortened using `directory-abbrev-alist'.
Same as `abbreviate-file-name' but disables `tramp-mode'. This
prevents improper processing of hargs with colons in them,
e.g. `actypes::link-to-file'."
(let (tramp-mode)
(abbreviate-file-name path)))
(defun hpath:absolute-arguments (actype arg-list &optional default-dirs)
"Return any paths in ACTYPE's ARG-LIST made absolute.
Uses optional DEFAULT-DIRS (a list of dirs or a single dir) or
`default-directory'. Other arguments are returned unchanged."
(let ((param-list (delq nil (mapcar (lambda (param)
(when param
(setq param (symbol-name param))
(unless (= ?& (aref param 0))
param)))
(action:params (actype:action actype))))))
;; Extend param-list to length of arg-list in case of any &rest param.
(setq param-list
(nconc param-list
(make-list (max 0 (- (length arg-list) (length param-list)))
(last param-list))))
(cl-mapcar (lambda (param arg)
(if (and (stringp param)
(or (string-match-p "file" param)
(string-match-p "dir" param)
(string-match-p "path" param)))
(hpath:absolute-to arg default-dirs)
arg))
param-list arg-list)))
(defun hpath:absolute-to (path &optional default-dirs)
"Return PATH as an absolute path relative to one directory.
Search optional DEFAULT-DIRS or `default-directory'.
Return PATH unchanged when it is absolute, a buffer name, not a valid path,
or when DEFAULT-DIRS is invalid. DEFAULT-DIRS when non-nil may be a single
directory or a list of directories. The first one in which PATH is found is
used."
(if (not (stringp path))
path
(hpath:call
(lambda (path non-exist)
(when (stringp path)
(setq path (hpath:trim path)))
(cond ((not (and (stringp path)
(not (hypb:object-p path))
(setq path (hpath:expand path))
(not (get-buffer path))
(not (file-name-absolute-p path))
(hpath:is-p path nil non-exist)))
path)
((not (cond ((null default-dirs)
(setq default-dirs (cons default-directory nil)))
((stringp default-dirs)
(setq default-dirs (cons default-dirs nil)))
((listp default-dirs))
(t nil)))
path)
(t
(let ((rtn) dir)
(while (and default-dirs (null rtn))
(setq dir (expand-file-name
(file-name-as-directory (car default-dirs)))
rtn (expand-file-name path dir)
default-dirs (cdr default-dirs))
(unless (file-exists-p rtn)
(setq rtn nil)))
(or rtn path)))))
path 'allow-spaces)))
(defun hpath:tramp-file-name-regexp ()
"Return a regexp for matching to the beginning of a remote file name.
Modifies `tramp-file-name-regexp' by removing bol anchor and
match to empty string if present."
(let* ((tramp-localname-regexp "[^[:cntrl:]]*\\'")
(tramp-regexp (car (if (fboundp 'tramp-file-name-structure)
(tramp-file-name-structure)
tramp-file-name-structure))))
(replace-regexp-in-string
"\\\\'" ""
(cond ((string-match-p "\\\\(\\?:^/\\\\)" tramp-regexp)
(replace-regexp-in-string "\\\\(\\?:\\^/\\\\)" "\\(?:/\\)" tramp-regexp nil t))
(t (substring tramp-regexp 1))))))
(defun hpath:remote-at-p ()
"Return a remote pathname that point is within or nil.
See the `(Emacs)Remote Files' info documentation for pathname format details.
Always returns nil if (hpath:remote-available-p) returns nil."
(let ((remote-package (hpath:remote-available-p))
(user (hpath:remote-default-user))
path
path-no-site)
(when remote-package
(setq path
(save-excursion
(skip-chars-backward "^[ \t\n\r\f\"`'|\(\{<")
(cond
((and (eq remote-package 'tramp)
(looking-at (hpath:tramp-file-name-regexp)))
(match-string-no-properties 0))
((looking-at hpath:url-regexp)
(if (string-match-p "\\`s?ftp\\'" (match-string-no-properties hpath:protocol-grpn))
(concat
(format "/%s:" (match-string-no-properties hpath:protocol-grpn))
;; user
(if (match-beginning hpath:username-grpn)
(match-string-no-properties hpath:username-grpn)
(concat user "@"))
;; sitename
(hpath:delete-trailer
(match-string-no-properties hpath:sitename-grpn))
":"
;; path
(if (match-beginning hpath:pathname-grpn)
(match-string-no-properties hpath:pathname-grpn)))
;; else ignore this other type of WWW path
))
((or (looking-at hpath:url-regexp2)
(looking-at hpath:url-regexp3))
(if (string-match-p "\\`s?ftp\\'" (match-string-no-properties hpath:hostname-grpn))
(concat
(format "/%s:" (match-string-no-properties hpath:hostname-grpn))
user "@"
;; site
(hpath:delete-trailer
(match-string-no-properties hpath:sitename-grpn))
":"
;; path
(if (match-beginning hpath:pathname-grpn)
(match-string-no-properties hpath:pathname-grpn)))
;; else ignore this other type of WWW path
))
;; user, site and path
((looking-at "/?[^/:@ \t\n\r\"`'|]+@[^/:@ \t\n\r\"`'|]+:[^]@ \t\n\r\"`'|\)\}]+")
(match-string-no-properties 0))
;; @site and path
((looking-at "@[^/:@ \t\n\r\"`'|]+:[^]@:, \t\n\r\"`'|\)\}]+")
(concat "/" user (match-string-no-properties 0)))
;; site and path
((and (looking-at
"/?\\(\\([^/:@ \t\n\r\"`'|]+\\):\\([^]@:, \t\n\r\"`'|\)\}]+\\)\\)[] \t\n\r,.\"`'|\)\}]")
(setq path (match-string-no-properties 1) ;; includes site
path-no-site (match-string-no-properties 3))
(string-match "[^.]\\.[^.]" (match-string-no-properties 2))
(not (string-match "\\(\\`\\|:\\)[:0-9]+\\'" path-no-site))) ;; prevent matching to line:col suffixes
(concat "/" user "@" path))
;; host and path
((and (looking-at "/\\([^/:@ \t\n\r\"`'|]+:[^]@:, \t\n\r\"`'|\)\}]+\\)")
(setq path (match-string-no-properties 1)))
(concat "/" user "@" path)))))
(hpath:delete-trailer path))))
(defun hpath:remote-p (path)
"Return a normalized form of PATH if a remote, non-local, pathname, else nil.
See the `(Tramp)Top' Emacs Lisp package manual for remote
pathname format details. Always returns nil
if (hpath:remote-available-p) returns nil."
(and (stringp path)
(let ((remote-package (hpath:remote-available-p))
(user (hpath:remote-default-user))
result)
(setq result
(cond
((null remote-package) nil)
((eq remote-package 'tramp)
(if (tramp-tramp-file-p path) path))
((string-match hpath:string-url-regexp path)
(if (string-match-p "\\`s?ftp\\'" (match-string-no-properties hpath:protocol-grpn path))
(concat
"/"
;; user
(if (match-beginning hpath:username-grpn)
(match-string-no-properties hpath:username-grpn path)
(concat user "@"))
;; site
(hpath:delete-trailer
(match-string-no-properties hpath:sitename-grpn path))
":"
;; path
(if (match-beginning hpath:pathname-grpn)
(match-string-no-properties hpath:pathname-grpn path)))
;; else ignore this other type of WWW path
))
((or (string-match hpath:string-url-regexp2 path)
(string-match hpath:string-url-regexp3 path))
(if (string-match-p "\\`s?ftp\\'"
(match-string-no-properties hpath:hostname-grpn path))
(concat
"/" user "@"
;; site
(hpath:delete-trailer
(match-string-no-properties hpath:sitename-grpn path))
":"
;; path
(if (match-beginning hpath:pathname-grpn)
(match-string-no-properties hpath:pathname-grpn path)))
;; else ignore this other type of WWW path
))
;; user, site and path
((string-match "/?[^/:@ \t\n\r\"`'|]+@[^/:@ \t\n\r\"`'|]+:[^]@ \t\n\r\"`'|\)\}]*"
path)
(match-string-no-properties 0 path))
;; @site and path
((string-match "@[^/:@ \t\n\r\"`'|]+:[^]@ \t\n\r\"`'|\)\}]*"
path)
(concat "/" user (match-string-no-properties 0 path)))
;; site and path
((and (string-match
"/?\\(\\([^/:@ \t\n\r\"`'|]+\\):[^]@:, \t\n\r\"`'|\)\}]*\\)"
path)
(setq result (match-string-no-properties 1 path))
(string-match "[^.]\\.[^.]"
(match-string-no-properties 2 path)))
(concat "/" user "@" result))
;; host and path
((and (string-match
"/\\([^/:@ \t\n\r\"`'|]+:[^]@:, \t\n\r\"`'|\)\}]*\\)"
path)
(setq result (match-string-no-properties 1 path)))
(concat "/" user "@" result))))
(hpath:delete-trailer result))))
(defun hpath:at-p (&optional type non-exist)
"Return delimited path or non-delimited remote path at point, if any.
Path is expanded and normalized. See `hpath:is-p' for how the path
is normalized.
World-Wide Web urls are ignored and therefore dealt with by other
code. Delimiters may be: double quotes, open and close single
quote, whitespace, or Texinfo file references. If optional TYPE
is the symbol \\='file or \\='directory, then only that path type
is accepted as a match. Only locally reachable paths are checked
for existence. With optional NON-EXIST, nonexistent local paths
are allowed. Absolute pathnames must begin with a `/' or `~'."
(let ((path (hpath:delimited-possible-path non-exist))
subpath)
(when path
(setq path (string-trim path)))
(when (and path (not non-exist) (string-match hpath:prefix-regexp path)
(not (string-equal (match-string 0 path) path)))
(setq non-exist t))
(if (and path (not (string-empty-p path)) (file-readable-p path))
path
(unless (and path (or (string-empty-p path)
(string-match "::" path)))
(cond ((and path
;; Don't allow more than one set of grouping chars
(not (string-match-p "\)\\s-*\(\\|\\]\\s-*\\[\\|\}\\s-*\{" path))
;; With point inside a path variable, return the path that point is on or to the right of.
(setq subpath (or (and (setq subpath (hargs:delimited "[:\"\']\\|^\\s-*" "[:\"\']\\|\\s-*$" t t nil "[\t\n\r\f]\\|[;:] \\| [;:]"))
(not (string-match-p "[:;\t\n\r\f]" subpath))
subpath)
(and (setq subpath (hargs:delimited "[;\"\']\\|^\\s-*" "[;\"\']\\|\\s-*$" t t nil "[\t\n\r\f]\\|[;:] \\| [;:]"))
(not (string-match-p "[;\t\n\r\f]\\|:[^:]*:" subpath))
subpath)))
;; Handle anchored or action prefix char paths in the
;; following clause; otherwise, might just be looking
;; at part of the path
(and subpath (not (or (string-match-p "#" subpath)
(string-match-p hpath:prefix-regexp subpath))))
(setq subpath
(if subpath
(cond ((and (string-match "\\`\\s-*\\([^; \t]+\\)" subpath)
(executable-find (match-string 1 subpath)))
;; Could be a shell command from a semicolon separated
;; list; ignore if so
nil)
(t (expand-file-name subpath)))
;; Only default to current path if know are within a PATH value
(when (string-match-p hpath:path-variable-value-regexp path)
".")))
(hpath:is-p subpath type non-exist))
subpath)
((hpath:is-p path type non-exist))
;; Local file URLs
;; ((hpath:is-p (hargs:delimited "file://" "[ \t\n\r\"\'\}]" nil t)))
((hpath:remote-at-p))
((hpath:www-at-p) nil))))))
(defun hpath:call (func path &optional non-exist)
"Call FUNC with a PATH and optional NON-EXIST flag.
Path is stripped of any prefix operator and suffix location,