diff --git a/dired-x.el b/dired-x.el index b09ef90..d3b9dc9 100644 --- a/dired-x.el +++ b/dired-x.el @@ -1482,37 +1482,6 @@ a prefix argument, when it offers the filename near point as a default." ;;; Internal functions. -;; Fixme: This should probably use `thing-at-point'. -- fx -(defun dired-filename-at-point () - "Return the filename closest to point, expanded. -Point should be in or after a filename." - (save-excursion - ;; First see if just past a filename. - (or (eobp) ; why? - (when (looking-at-p "[] \t\n[{}()]") ; whitespace or some parens - (skip-chars-backward " \n\t\r({[]})") - (or (bobp) (backward-char 1)))) - (let ((filename-chars "-.[:alnum:]_/:$+@") - start prefix) - (if (looking-at-p (format "[%s]" filename-chars)) - (progn - (skip-chars-backward filename-chars) - (setq start (point) - prefix - ;; This is something to do with ange-ftp filenames. - ;; It convert foo@bar to /foo@bar. - ;; But when does the former occur in dired buffers? - (and (string-match-p - "^\\w+@" - (buffer-substring start (line-end-position))) - "/")) - (if (string-match-p "[/~]" (char-to-string (preceding-char))) - (setq start (1- start))) - (skip-chars-forward filename-chars)) - (error "No file found around point!")) - ;; Return string. - (expand-file-name (concat prefix (buffer-substring start (point))))))) - (defun dired-x-read-filename-at-point (prompt) "Return filename prompting with PROMPT with completion. If `current-prefix-arg' is non-nil, uses name at point as guess." diff --git a/dired.el b/dired.el index 2ecd6bd..69aa41d 100644 --- a/dired.el +++ b/dired.el @@ -958,16 +958,31 @@ ERROR can be a string with the error message." ;; (read-file-name (format "Dired %s(directory): " str) ;; nil default-directory nil)))))))) -(defun dired-file-name-at-point () - "Try to get a file name at point in the current dired buffer. -This hook is intended to be put in `file-name-at-point-functions'. -Note that it returns an abbreviated name that can't be used -as an argument to `dired-goto-file'." +(defun dired-filename-at-point-abbrev () + "Return the filename closest to point, abbreviated. +Point should be in or after a filename. Do not confuse this +function with `dired-filename-at-point', which expands +the file name." (let ((filename (dired-get-filename nil t))) (when filename - (if (file-directory-p filename) - (file-name-as-directory (abbreviate-file-name filename)) - (abbreviate-file-name filename))))) + (abbreviate-file-name + (if (file-directory-p filename) + (file-name-as-directory filename) + filename))))) +(defalias 'dired-file-name-at-point 'dired-filename-at-point-abbrev) + +(defun dired-filename-at-point-expand () + "Return the filename closest to point, expanded. +Point should be in or after a filename. Do not confuse this +function with `dired-file-name-at-point', which abbreviates +the file name." + (let ((filename (dired-get-filename nil t))) + (when filename + (expand-file-name + (if (file-directory-p filename) + (file-name-as-directory filename) + filename))))) +(defalias 'dired-filename-at-point 'dired-filename-at-point-expand) (defun dired-grep-read-files () "Use file at point as the file for grep's default file-name pattern suggestion.