Subject: Re: bug#16477: 24.3.50; [saveplace] symbol's function defn is void: dired-get-filename

From: Juri Linkov <[email-masked]>
Date: Fri, 17 Jan 2014 10:01:46 +0200

> (setq-default save-place t)
> (require 'saveplace)
> (eshell)
> (kill-emacs)
> Debugger entered--Lisp error: (void-function dired-get-filename)
>   dired-get-filename(nil t)
>   save-place-to-alist()
>   save-places-to-alist()
>   save-place-kill-emacs-hook()
>   kill-emacs()
>   eval((kill-emacs) nil)
>   eval-expression((kill-emacs) nil)
>   call-interactively(eval-expression nil nil)
>   command-execute(eval-expression)

Thanks for the report.  `eshell' sets the variable `dired-directory',
so we have to check if we are in dired mode as well:

=== modified file 'lisp/saveplace.el'
--- lisp/saveplace.el	2014-01-01 07:43:34 +0000
+++ lisp/saveplace.el	2014-01-17 08:01:20 +0000
@@ -152,7 +152,8 @@ (defun toggle-save-place (&optional parg
 
 \(setq-default save-place t\)"
   (interactive "P")
-  (if (not (or buffer-file-name dired-directory))
+  (if (not (or buffer-file-name (and (derived-mode-p 'dired-mode)
+				     dired-directory)))
       (message "Buffer `%s' not visiting a file or directory" (buffer-name))
     (if (and save-place (or (not parg) (<= parg 0)))
 	(progn
@@ -172,7 +173,8 @@ (defun save-place-to-alist ()
   ;; will be saved again when Emacs is killed.
   (or save-place-loaded (load-save-place-alist-from-file))
   (let ((item (or buffer-file-name
-                  (and dired-directory
+                  (and (derived-mode-p 'dired-mode)
+		       dired-directory
 		       (if (consp dired-directory)
 			   (expand-file-name (car dired-directory))
 			 (expand-file-name dired-directory))))))
@@ -184,7 +186,8 @@ (defun save-place-to-alist ()
             (position (cond ((eq major-mode 'hexl-mode)
 			     (with-no-warnings
 			       (1+ (hexl-current-address))))
-			    (dired-directory
+			    ((and (derived-mode-p 'dired-mode)
+				  dired-directory)
 			     (let ((filename (dired-get-filename nil t)))
 			       (if filename
 				   `((dired-filename . ,filename))
@@ -301,7 +304,8 @@ (defun save-places-to-alist ()
       (with-current-buffer (car buf-list)
 	;; save-place checks buffer-file-name too, but we can avoid
 	;; overhead of function call by checking here too.
-	(and (or buffer-file-name dired-directory)
+	(and (or buffer-file-name (and (derived-mode-p 'dired-mode)
+				       dired-directory))
 	     (save-place-to-alist))
 	(setq buf-list (cdr buf-list))))))
 
@@ -321,9 +325,11 @@ (declare-function dired-goto-file "dired
 (defun save-place-dired-hook ()
   "Position the point in a dired buffer."
   (or save-place-loaded (load-save-place-alist-from-file))
-  (let ((cell (assoc (if (consp dired-directory)
-			 (expand-file-name (car dired-directory))
-		       (expand-file-name dired-directory))
+  (let ((cell (assoc (and (derived-mode-p 'dired-mode)
+			  dired-directory
+			  (if (consp dired-directory)
+			      (expand-file-name (car dired-directory))
+			    (expand-file-name dired-directory)))
 		     save-place-alist)))
     (if cell
         (progn