Function: hpath:delimited-possible-path

hpath:delimited-possible-path is a byte-compiled function defined in hpath.el.

Signature

(hpath:delimited-possible-path &optional NON-EXIST INCLUDE-POSITIONS)

Documentation

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: double quotes, open and close single quote, whitespace, or Texinfo file references.

With optional NON-EXIST, nonexistent local paths are allowed. Absolute pathnames must begin with a / or ~.

With optional INCLUDE-POSITIONS, return a triplet list of (path start-pos end-pos) or nil.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hpath.el
(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: double quotes, open and close single quote, whitespace,
or Texinfo file references.

With optional NON-EXIST, nonexistent local paths are allowed.
Absolute pathnames must begin with a `/' or `~'.

With optional INCLUDE-POSITIONS, return a triplet list of (path start-pos
end-pos) or nil."
  (unless (eolp)
    ;; Prevents MSWindows to Posix path substitution
    (let* ((hyperb:microsoft-os-p t)
	   (triplet (or (hargs:delimited "file://" "\\s-" nil t include-positions)
			;; Filenames in HTML
			(hargs:delimited """ """ nil nil include-positions "[`'’]")
			;; Embedded double quoted filenames
			(hargs:delimited "\\\"" "\\\"" nil nil include-positions "[`'’]")
			;; Filenames in TexInfo docs
			(hargs:delimited "@file{" "}" nil nil include-positions)
			(and (hypb:in-string-p)
			     (or
			      ;; Double quoted filenames
			      (hargs:delimited "\"" "\"" nil nil include-positions "[`'’]")
			      ;; Filenames in Info docs, Python files or 'ls' listing files in
			      ;; single quotes
			      (hargs:delimited "[`'‘]" "[`'’]" t t include-positions "\"")))))
	   (p (if (listp triplet) (car triplet) triplet)))
      (if non-exist
	  ;; This may be a triplet of (path start-pos end-pos) or just path
	  triplet
	;; If `non-exist' and 'triplet' are nil, look for any
	;; existing whitespace delimited filename at point.  If
	;; match consists of punctuation only, like . or ..,
	;; don't treat it as a pathname.
	(when (null triplet)
	  (let* ((space-delimiter "[ \t]"))
	    (setq triplet (hargs:delimited (format "^\\|\\(%s\\|[\]\[()<>\;&,@]\\)+"
						   space-delimiter)
					   "\\([\]\[()<>\;&,@]\\|:*\\s-\\)+\\|$"
					   t t t)
		  p (car triplet))))
	;; May have matched to a string with an embedded double
	;; quote or surrounded by braces; if so, don't consider it a path.
	;; Also ignore whitespace delimited root dirs, e.g. " / ".
	(when (and (stringp p) (not (string-match-p "\\`{.*}\\'\\|\"\\|\\`[/\\]+\\'" p))
		   (delq nil (mapcar (lambda (c) (/= (char-syntax ?.) (char-syntax c))) p)))
	  ;; Prepend proper directory from cd, ls *, recursive ls or dir file
	  ;; listings when needed.
	  (setq p (string-trim p)
		p (or (hpath:prepend-shell-directory p) p))
	  (if include-positions
	      (progn (setcar triplet p)
		     triplet)
	    p))))))