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".

  • 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+, 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
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 "+")))
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.