I'm trying to get hold of the current filename at point. In an arbitrary buffer.
Say I have list of files in a buffer and I want to be able to do something with each file. For that I need to determine filenames
That's easy you may say, just use
(thing-at-point 'filename), and you'd be right, unfortunately that thing simply can't detect filenames with spaces in them.
So, here's the output of
I turned whitespace-mode and saw this:
So I've figured - I need to hold onto the thing at point that separated by double whitespace at both ends.
Or to be precise:
Can someone help me with that? Thanks!
I looked into
buffer-substring-no-properties, but couldn't figure out how to apply for my thing,
re-search-backward is probably what I need to use, but I can't figure out the correct regex. Damn, regexes in elisp are wild and untamable.
update: Attempting this:
(defun get-filename () (interactive) (save-excursion (let* ((start (re-search-backward "\s\s\\|^")) (end (re-search-forward "\s\s\\|$"))) (buffer-substring-no-properties start end))))
and it's not working ;(
update 2: This worked:
(defun get-filename () (interactive) (let ((start (save-excursion (re-search-backward "\s\s\\|^"))) (end (save-excursion (re-search-forward "\s\s\\|$")))) (string-trim (buffer-substring-no-properties start end))))