aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/ffap.el
diff options
context:
space:
mode:
authorVibhav Pant2020-08-21 14:04:35 +0530
committerVibhav Pant2020-08-21 14:04:35 +0530
commitf0f8d7b82492e741950c363a03b886965c91b1b0 (patch)
tree19b716830b1ebabc0d7d75949c4e6800c0f104ad /lisp/ffap.el
parent9e64a087c4d167e7ec1c4e22bea3e6af53b563de (diff)
parentc818c29771d3cb51875643b2f6c894073e429dd2 (diff)
downloademacs-feature/native-comp-macos-fixes.tar.gz
emacs-feature/native-comp-macos-fixes.zip
Merge branch 'feature/native-comp' into feature/native-comp-macos-fixesfeature/native-comp-macos-fixes
Diffstat (limited to 'lisp/ffap.el')
-rw-r--r--lisp/ffap.el139
1 files changed, 130 insertions, 9 deletions
diff --git a/lisp/ffap.el b/lisp/ffap.el
index ceba9d26223..28f566dd93a 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -1109,6 +1109,121 @@ The arguments CHARS, BEG and END are handled as described in
1109 ;; Added at suggestion of RHOGEE (for ff-paths), 7/24/95. 1109 ;; Added at suggestion of RHOGEE (for ff-paths), 7/24/95.
1110 "Last string returned by the function `ffap-string-at-point'.") 1110 "Last string returned by the function `ffap-string-at-point'.")
1111 1111
1112(defcustom ffap-file-name-with-spaces nil
1113 "If non-nil, enable looking for paths with spaces in `ffap-string-at-point'.
1114Enabling this variable may lead to `find-file-at-point' guessing
1115wrong more often when trying to find a file name intermingled
1116with normal text, but can be useful when working on systems that
1117normally use spaces in file names (like Microsoft Windows and the
1118like)."
1119 :type 'boolean
1120 :version "28.1")
1121
1122(defun ffap-search-backward-file-end (&optional dir-separator end)
1123 "Search backward position point where file would probably end.
1124Optional DIR-SEPARATOR defaults to \"/\". The search maximum is
1125`line-end-position' or optional END point.
1126
1127Suppose the cursor is somewhere that might be near end of file,
1128the guessing would position point before punctuation (like comma)
1129after the file extension:
1130
1131 C:\temp\file.log, which contain ....
1132 =============================== (before)
1133 ---------------- (after)
1134
1135
1136 C:\temp\file.log on Windows or /tmp/file.log on Unix
1137 =============================== (before)
1138 ---------------- (after)
1139
1140The strategy is to search backward until DIR-SEPARATOR which defaults to
1141\"/\" and then take educated guesses.
1142
1143Move point and return point if an adjustment was done."
1144 (unless dir-separator
1145 (setq dir-separator "/"))
1146 (let ((opoint (point))
1147 point punct end whitespace-p)
1148 (when (re-search-backward
1149 (regexp-quote dir-separator) (line-beginning-position) t)
1150 ;; Move to the beginning of the match..
1151 (forward-char 1)
1152 ;; ... until typical punctuation.
1153 (when (re-search-forward "\\([][<>()\"'`,.:;]\\)"
1154 (or end
1155 (line-end-position))
1156 t)
1157 (setq end (match-end 0))
1158 (setq punct (match-string 1))
1159 (setq whitespace-p (looking-at "[ \t\r\n]\\|$"))
1160 (goto-char end)
1161 (cond
1162 ((and (string-equal punct ".")
1163 whitespace-p) ;end of sentence
1164 (setq point (1- (point))))
1165 ((and (string-equal punct ".")
1166 (looking-at "[a-zA-Z0-9.]+")) ;possibly file extension
1167 (setq point (match-end 0)))
1168 (t
1169 (setq point (point)))))
1170 (goto-char opoint)
1171 (when point
1172 (goto-char point)
1173 point))))
1174
1175(defun ffap-search-forward-file-end (&optional dir-separator)
1176 "Search DIR-SEPARATOR and position point at file's maximum ending.
1177This includes spaces.
1178Optional DIR-SEPARATOR defaults to \"/\".
1179Call `ffap-search-backward-file-end' to refine the ending point."
1180 (unless dir-separator
1181 (setq dir-separator "/"))
1182 (let* ((chars ;expected chars in file name
1183 (concat "[^][^<>()\"'`;,#*|"
1184 ;; exclude the opposite as we know the separator
1185 (if (string-equal dir-separator "/")
1186 "\\\\"
1187 "/")
1188 "\t\r\n]"))
1189 (re (concat
1190 chars "*"
1191 (if dir-separator
1192 (regexp-quote dir-separator)
1193 "/")
1194 chars "*")))
1195 (when (looking-at re)
1196 (goto-char (match-end 0)))))
1197
1198(defun ffap-dir-separator-near-point ()
1199 "Search backward and forward for closest slash or backlash in line.
1200Return string slash or backslash. Point is moved to closest position."
1201 (let ((point (point))
1202 str pos)
1203 (when (looking-at ".*?/")
1204 (setq str "/"
1205 pos (match-end 0)))
1206 (when (and (looking-at ".*?\\\\")
1207 (or (null pos)
1208 (< (match-end 0) pos)))
1209 (setq str "\\"
1210 pos (match-end 0)))
1211 (goto-char point)
1212 (when (and (re-search-backward "/" (line-beginning-position) t)
1213 (or (null pos)
1214 (< (- point (point)) (- pos point))))
1215 (setq str "/"
1216 pos (1+ (point)))) ;1+ to keep cursor at the end of char
1217 (goto-char point)
1218 (when (and (re-search-backward "\\\\" (line-beginning-position) t)
1219 (or (null pos)
1220 (< (- point (point)) (- pos point))))
1221 (setq str "\\"
1222 pos (1+ (point))))
1223 (when pos
1224 (goto-char pos))
1225 str))
1226
1112(defun ffap-string-at-point (&optional mode) 1227(defun ffap-string-at-point (&optional mode)
1113 "Return a string of characters from around point. 1228 "Return a string of characters from around point.
1114 1229
@@ -1128,7 +1243,8 @@ Set the variables `ffap-string-at-point' and
1128 1243
1129When the region is active and larger than `ffap-max-region-length', 1244When the region is active and larger than `ffap-max-region-length',
1130return an empty string, and set `ffap-string-at-point-region' to '(1 1)." 1245return an empty string, and set `ffap-string-at-point-region' to '(1 1)."
1131 (let* ((args 1246 (let* (dir-separator
1247 (args
1132 (cdr 1248 (cdr
1133 (or (assq (or mode major-mode) ffap-string-at-point-mode-alist) 1249 (or (assq (or mode major-mode) ffap-string-at-point-mode-alist)
1134 (assq 'file ffap-string-at-point-mode-alist)))) 1250 (assq 'file ffap-string-at-point-mode-alist))))
@@ -1137,14 +1253,25 @@ return an empty string, and set `ffap-string-at-point-region' to '(1 1)."
1137 (beg (if region-selected 1253 (beg (if region-selected
1138 (region-beginning) 1254 (region-beginning)
1139 (save-excursion 1255 (save-excursion
1140 (skip-chars-backward (car args)) 1256 (if (and ffap-file-name-with-spaces
1141 (skip-chars-forward (nth 1 args) pt) 1257 (memq mode '(nil file)))
1258 (when (setq dir-separator (ffap-dir-separator-near-point))
1259 (while (re-search-backward
1260 (regexp-quote dir-separator)
1261 (line-beginning-position) t)
1262 (goto-char (match-beginning 0))))
1263 (skip-chars-backward (car args))
1264 (skip-chars-forward (nth 1 args) pt))
1142 (point)))) 1265 (point))))
1143 (end (if region-selected 1266 (end (if region-selected
1144 (region-end) 1267 (region-end)
1145 (save-excursion 1268 (save-excursion
1146 (skip-chars-forward (car args)) 1269 (skip-chars-forward (car args))
1147 (skip-chars-backward (nth 2 args) pt) 1270 (skip-chars-backward (nth 2 args) pt)
1271 (when (and ffap-file-name-with-spaces
1272 (memq mode '(nil file)))
1273 (ffap-search-forward-file-end dir-separator)
1274 (ffap-search-backward-file-end dir-separator))
1148 (point)))) 1275 (point))))
1149 (region-len (- (max beg end) (min beg end)))) 1276 (region-len (- (max beg end) (min beg end))))
1150 1277
@@ -1825,12 +1952,6 @@ Only intended for interactive use."
1825(defalias 'find-file-literally-at-point 'ffap-literally) 1952(defalias 'find-file-literally-at-point 'ffap-literally)
1826 1953
1827 1954
1828;;; Bug Reporter:
1829
1830(define-obsolete-function-alias 'ffap-bug 'report-emacs-bug "23.1")
1831(define-obsolete-function-alias 'ffap-submit-bug 'report-emacs-bug "23.1")
1832
1833
1834;;; Hooks for Gnus, VM, Rmail: 1955;;; Hooks for Gnus, VM, Rmail:
1835;; 1956;;
1836;; If you do not like these bindings, write versions with whatever 1957;; If you do not like these bindings, write versions with whatever