Function: ffap-search-backward-file-end
ffap-search-backward-file-end is a byte-compiled function defined in
ffap.el.gz.
Signature
(ffap-search-backward-file-end &optional DIR-SEPARATOR END)
Documentation
Search backward position point where file would probably end.
Optional DIR-SEPARATOR defaults to "/". The search maximum is
line-end-position or optional END point.
Suppose the cursor is somewhere that might be near end of file, the guessing would position point before punctuation (like comma) after the file extension:
C:\temp\file.log, which contain ....
=============================== (before)
---------------- (after)
C:\temp\file.log on Windows or /tmp/file.log on Unix
=============================== (before)
---------------- (after)
The strategy is to search backward until DIR-SEPARATOR which defaults to
"/" and then take educated guesses.
Move point and return point if an adjustment was done.
Source Code
;; Defined in /usr/src/emacs/lisp/ffap.el.gz
(defun ffap-search-backward-file-end (&optional dir-separator end)
"Search backward position point where file would probably end.
Optional DIR-SEPARATOR defaults to \"/\". The search maximum is
`line-end-position' or optional END point.
Suppose the cursor is somewhere that might be near end of file,
the guessing would position point before punctuation (like comma)
after the file extension:
C:\\temp\\file.log, which contain ....
=============================== (before)
---------------- (after)
C:\\temp\\file.log on Windows or /tmp/file.log on Unix
=============================== (before)
---------------- (after)
The strategy is to search backward until DIR-SEPARATOR which defaults to
\"/\" and then take educated guesses.
Move point and return point if an adjustment was done."
(unless dir-separator
(setq dir-separator "/"))
(let ((opoint (point))
point punct whitespace-p)
(when (re-search-backward
(regexp-quote dir-separator) (line-beginning-position) t)
;; Move to the beginning of the match..
(forward-char 1)
;; ... until typical punctuation.
(when (re-search-forward "\\([][<>()\"'`,.:;]\\)"
(or end
(line-end-position))
t)
(setq end (match-end 0))
(setq punct (match-string 1))
(setq whitespace-p (looking-at "[ \t\r\n]\\|$"))
(goto-char end)
(cond
((and (string-equal punct ".")
whitespace-p) ;end of sentence
(setq point (1- (point))))
((and (string-equal punct ".")
(looking-at "[a-zA-Z0-9.]+")) ;possibly file extension
(setq point (match-end 0)))
(t
(setq point (point)))))
(goto-char opoint)
(when point
(goto-char point)
point))))