3

Why does thing-at-point not consider + as a filename character?

For example:

(defun my-get-filename-at-point ()
  (interactive)
  (message (thing-at-point 'filename t)))

and consider the cursor positioned at the filename bookmark+-1.el in the buffer. Running M-: (my-get-filename-at-point) will either return "bookmark" or "-1.el".

Drew
  • 75,699
  • 9
  • 109
  • 225
Håkon Hægland
  • 3,608
  • 1
  • 20
  • 51
  • 2
    Please consider filing an Emacs bug for this. Perhaps there is some good reason why `+` is not included in `thing-at-point-file-name-chars`, but that's not clear at all. What's more, I'm guessing that the allowed chars might depend on the platform, and in that case an enhancement would be for Emacs to determine the default value better, taking the platform into account. `M-x report-emacs-bug`. – Drew Jun 10 '17 at 22:51
  • 1
    Thing-at-point is probably not the best way to pick up a file name at point. You might want to use `ffap-guesser` (or, since you seem to be using [Bookmark+](https://www.emacswiki.org/emacs/BookmarkPlus), `bmk-ffap-guesser`. Library **`ffap.el`** is **all about** getting and using a file name (or a url) at point, whereas `thing-at-point` for `filename` is pretty rudimentary. – Drew Jun 10 '17 at 22:56
  • There are no real restrictions on the characters that can be in filenames. The default set of characters that `thing-at-point` uses is a heuristic to match common file naming styles. – Barmar Jun 10 '17 at 23:49

2 Answers2

4

Not sure why it's not in the default set of chars but you can add it yourself. The relevant variable is thing-at-point-file-name-chars.

For example:

(eval-after-load "thingatpt"
  (setq thing-at-point-file-name-chars (concat thing-at-point-file-name-chars "+")))
glucas
  • 20,175
  • 1
  • 51
  • 83
2

because in thingatpt.el the var thing-at-point-file-name-chars is defined:

(defvar thing-at-point-file-name-chars "-~/[:alnum:]_.${}#%,:"
  "Characters allowable in filenames.")

If you set it, that the + is added to the chars, like so:

(setq thing-at-point-file-name-chars "-~/[:alnum:]_.${}#%,:+")

then it works like you want it to.

jue
  • 4,476
  • 8
  • 20