Subject: bug#60097: 29.0.60; emacsclient adds unabbreviated names to file-name-history

From: Eli Zaretskii <[email-masked]>
Date: Sat, 17 Dec 2022 14:48:36 +0200

> From: Augusto Stoffel <[email-masked]>
> Date: Thu, 15 Dec 2022 19:14:45 +0100
> 
> 
> 1. Start emacs -Q
> 2. M-x server-start RET
> 3. In a terminal, type /home/user/somefile

I guess you meant to type "emacsclient /home/user/somefile"?

> Then "/home/user/somefile" is added to file-name-history.  I would
> instead expect the abbreviated name, "~/somefile", to be added to
> history.

Does the patch below do what you want?

Btw, we don't do this consistently: "C-x C-f" doesn't record the
abbreviated file name, it records the original one.

diff --git a/lisp/server.el b/lisp/server.el
index fd740d1..d963ee5 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -1495,7 +1495,7 @@ server-visit-files
 					  minibuffer-auto-raise))
 	       (filen (car file))
 	       (obuf (get-file-buffer filen)))
-	  (add-to-history 'file-name-history filen)
+          (file-name-history--add filen)
 	  (if (null obuf)
 	      (progn
 		(run-hooks 'pre-command-hook)