From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: tilde in dired default-directory but not elsewhere Date: Wed, 09 Jul 2014 18:47:37 +0200 Organization: Aioe.org NNTP Server Message-ID: <87tx6qqy1i.fsf@debian.uxu> References: <87fvickfy2.fsf@debian.uxu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1404951050 30051 80.91.229.3 (10 Jul 2014 00:10:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 10 Jul 2014 00:10:50 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jul 10 02:10:43 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1X51wg-00005G-K9 for geh-help-gnu-emacs@m.gmane.org; Thu, 10 Jul 2014 02:10:42 +0200 Original-Received: from localhost ([::1]:32872 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4v51-0005VU-Bj for geh-help-gnu-emacs@m.gmane.org; Wed, 09 Jul 2014 12:50:51 -0400 Original-Path: usenet.stanford.edu!goblin3!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 78 Original-NNTP-Posting-Host: SIvZRMPqRkkTHAHL6NkRuw.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:Udy7rdAqD3v/pl4xk9b6i/jZvhE= Mail-Copies-To: never Original-Xref: usenet.stanford.edu gnu.emacs.help:206334 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:98609 Archived-At: Michael Heerdegen writes: > Due to the doc, it is unspecified, which means both > cases are ok. OK, in my case they show up differently in the mode line so it is something I'd like to fix. By the way the tilde can be annoying in quite a few cases, not just in Emacs. You'd think for some source that is "only you" (no sudo, setuid, etc.) it'd just work with tilde in the source. But it doesn't and it is frustrating because you think there is a bug somewhere else. Then you change the tilde to the path and it works. In Emacs I can't recall it has been a problem except for one case. I wanted a defun that would kill the path of the file shown in a buffer. That way, I could write a message on half the screen, and look at the file (buffer) on the other half, and were I to mention the selfsame file in the message, I'd just kill and yank the path. Normally I always preach about how educational (and pleasant) it is not to be lazy and to type everything. But here I make an exception because paths, contrary to code, are so boring to type - and if it is boring, it is much easier to make mistakes which of course won't benefit the reader of the post... Anyway, I wrote some code to do that. Just looking at it, there is something itchy about it. This is also something I think definitely should be built-in (if it isn't) in one way or another. (defun get-tilde-path () (interactive) (let((path (buffer-file-name))) (if path (let*((sudo-prefix (format "/sudo:root@%s:" (message-make-domain))) (home-path (getenv "HOME")) (path-no-home (replace-regexp-in-string home-path "~" path)) (tilde-path (replace-regexp-in-string sudo-prefix "" path-no-home))) tilde-path ) ))) (defun kill-path () (interactive) (if (string= major-mode "dired-mode") (progn (kill-new dired-directory) (message " Directory path killed.") ) (let((path (get-tilde-path))) (if path (progn (kill-new (get-tilde-path)) (message " Path killed.") ) (prog1 nil (message " Can't kill path! (Why?)") ))))) > (Also note that default-directory is a buffer local > variable, and you didn't tell in your recipe in which > buffer you looked at the binding) Of course I didn't change the buffer in between: 1. emacs -Q 2. C-h v default-directory RET 3. C-x C-f test.el RET 4. point 2, again > I think you should use `abbreviate-file-name` in your > mode-line expression. OK, I'll try that. -- underground experts united