Function: hpath:is-p
hpath:is-p is a byte-compiled function defined in hpath.el.
Signature
(hpath:is-p PATH &optional TYPE NON-EXIST)
Documentation
Return normalized PATH if PATH is a Posix or MSWindows path, else nil.
If optional TYPE is the symbol 'file or 'directory, then only that path type is accepted as a match. The existence of the path is checked only for locally reachable paths (Info paths are not checked).
Single spaces are permitted in the middle of existing pathnames, but not at the start or end. With optional NON-EXIST equal to t, nonexistent local paths without spaces are allowed. Set NON-EXIST to 'allow-spaces to allow spaces in non-existent paths.
Before the pathname is checked for existence, sequences of tabs and newlines are converted to a single space, hpath:prefix-regexp matches at the start are temporarily stripped, "file://" prefixes are 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.
Source Code
;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hpath.el
(defun hpath:is-p (path &optional type non-exist)
"Return normalized PATH if PATH is a Posix or MSWindows path, else nil.
If optional TYPE is the symbol \\='file or \\='directory, then
only that path type is accepted as a match. The existence of the
path is checked only for locally reachable paths (Info paths are
not checked).
Single spaces are permitted in the middle of existing pathnames, but not at
the start or end. With optional NON-EXIST equal to t, nonexistent local
paths without spaces are allowed. Set NON-EXIST to \\='allow-spaces to allow
spaces in non-existent paths.
Before the pathname is checked for existence, sequences of tabs and newlines
are converted to a single space, `hpath:prefix-regexp' matches at the start
are temporarily stripped, \"file://\" prefixes are 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)
(or
;; Due to the colons, "hui.el#save-excursion:I2:L2:C30",
;; will improperly match to a PATH variable. Ensure it doesn't.
(string-match hpath:instance-line-column-regexp path)
;; not a PATH variable type value
(not (string-match-p hpath:path-variable-value-regexp path)))
;; If a single character in length, must be a word or symbol character
(or (/= (length path) 1) (and (string-match-p "\\sw\\|\\s_" path)
(not (string-match-p "[@#&!*]" path)))))
(setq path (hpath:mswindows-to-posix path))
(unless (or (string-match-p "\\`[.~/]\\'" path)
(file-readable-p path))
(setq path (hpath:call
(lambda (path non-exist)
(let ((modifier nil)
suffix)
(and (not (or (string-equal path "")
(string-match-p "\\`\\s-\\|\\s-\\'" path)))
(or (not (string-match-p "[()]" path))
(string-match-p "\\`([^ \t\n\r\)]+)[ *A-Za-z0-9]" path))
;; Allow for @{ and @} in texinfo-mode
(or (when (string-match-p hpath:variable-regexp path)
;; Path may be a link reference with embedded
;; variables that must be expanded.
;; A variable may be a PATH-type variable
;; where the first matching expansion
;; that matches the full path must be utilized.
(setq path (hpath:substitute-value path)
non-exist t)) ;; Ensure non-existent path links handled as pathnames.
t)
(not (string-match-p "[\t\n\r\"`'|{}\\]" path))
(let ((rtn-path (concat path "%s")))
(and (or (not (hpath:www-p path))
(string-match-p "\\`s?ftp[:.]" path))
(let ((remote-path (string-match-p "\\(@.+:\\|^/.+:\\|..+:/\\).*[^:0-9/]" path)))
(when (cond (remote-path
(cond ((eq type 'file)
(not (string-equal "/" (substring path -1))))
((eq type 'directory)
(string-equal "/" (substring path -1)))
(t)))
((or (and non-exist
(or
;; Info or remote path, so don't check for.
(string-match-p "[()]" path)
(string-match-p ".+\\.info\\([.#]\\|\\'\\)" path)
(hpath:remote-p path)
(setq suffix (hpath:exists-p path t))
;; Don't allow spaces in non-existent pathnames
;; unless 'non-exist' equals 'allow-spaces.
(eq non-exist 'allow-spaces)
(not (string-match-p "\\s-" path))))
(setq suffix (hpath:exists-p path t)))
(cond ((eq type 'file)
(not (file-directory-p path)))
((eq type 'directory)
(file-directory-p path))
(t))))
;; Might be an encoded URL with % characters, so
;; decode it before calling format below.
(when (string-match-p "%" rtn-path)
(let (decoded-path)
(while (not (equal rtn-path (setq decoded-path (hypb:decode-url rtn-path))))
(setq rtn-path decoded-path))))
;; Quote any % except for one %s at the end of the
;; path part of rtn-path (immediately preceding a #
;; or , character or the end of string).
(setq rtn-path (replace-regexp-in-string "%" "%%" rtn-path t nil)
rtn-path (replace-regexp-in-string "%%s\\([#,]\\|\\'\\)" "%s\\1" rtn-path t nil))
;; Return path if non-nil return value.
(if (stringp suffix) ;; suffix could = t, which we ignore
(if (string-match (concat (regexp-quote suffix) "%s") rtn-path)
;; remove suffix
(concat (substring rtn-path 0 (match-beginning 0))
(substring rtn-path (match-end 0)))
;; add suffix
(concat modifier (format rtn-path suffix)))
(concat modifier (format rtn-path ""))))))))))
path non-exist)))
(unless (or (null path)
(string-empty-p path)
(string-equal "-" path)
(string-match-p "#['`\"]" path)
;; If a single character in length, must be a word or
;; symbol character other than [.~ /].
(and (= (length path) 1)
(not (string-match-p "\\`[.~/]\\'" path))
(or (not (string-match-p "\\sw\\|\\s_" path))
(string-match-p "[@#&!*]" path))))
(when (or non-exist (file-remote-p path)
(hpath:normalize path))
path))))