I'd like to write elisp function with the following functionality:
- It can be invoked from the minibuffer, and it will then relate to the latest selected window buffer.
- If the selected buffer is in dired-mode, it should insert the file pointed to by dired
- Otherwise insert the buffer name of the file
This is what I have got so far:
;; Doesn't work as intended when in minibuffer invoked from dired mode! (defun get-nondir-filename-from-dired-or-buffer () "Returns either the filename of the buffer or the file pointed to in a dired buffer" (interactive) (let* ((winbuf (window-buffer (minibuffer-selected-window)))) (insert (shell-quote-argument (file-name-nondirectory (if (eq (buffer-local-value 'major-mode winbuf) 'dired-mode) (dired-get-filename) ;; <- How can I get filename from dired? (buffer-file-name winbuf)))))))