From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Boruch Baum Newsgroups: gmane.emacs.bugs Subject: bug#43961: read carefully: dired-file-name-at-point vs dired-filename-at-point Date: Mon, 12 Oct 2020 10:26:38 -0400 Message-ID: <20201012142522.m24zmrzzuiiao4ck@E15-2016.optimum.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="aftfgvqp76s5o6ko" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6638"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: NeoMutt/20180716 To: 43961@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 12 16:30:04 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kRypw-0001e8-Dv for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 12 Oct 2020 16:30:04 +0200 Original-Received: from localhost ([::1]:55370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRypu-0006LZ-Vr for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 12 Oct 2020 10:30:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRynz-0004td-6L for bug-gnu-emacs@gnu.org; Mon, 12 Oct 2020 10:28:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60304) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kRyny-0006Dn-R5 for bug-gnu-emacs@gnu.org; Mon, 12 Oct 2020 10:28:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kRyny-0001xl-Je for bug-gnu-emacs@gnu.org; Mon, 12 Oct 2020 10:28:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Boruch Baum Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Oct 2020 14:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 43961 X-GNU-PR-Package: emacs X-Debbugs-Original-To: Emacs Bug Reporting Original-Received: via spool by submit@debbugs.gnu.org id=B.16025128497490 (code B ref -1); Mon, 12 Oct 2020 14:28:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Oct 2020 14:27:29 +0000 Original-Received: from localhost ([127.0.0.1]:43614 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kRynQ-0001wi-LO for submit@debbugs.gnu.org; Mon, 12 Oct 2020 10:27:28 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:38498) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kRynO-0001wW-Qs for submit@debbugs.gnu.org; Mon, 12 Oct 2020 10:27:27 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRynO-00040H-Ju for bug-gnu-emacs@gnu.org; Mon, 12 Oct 2020 10:27:26 -0400 Original-Received: from mout.gmx.net ([212.227.17.20]:43605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRymi-00063Y-Pn for bug-gnu-emacs@gnu.org; Mon, 12 Oct 2020 10:27:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1602512801; bh=aQjdN0oOpNe/GzJK/yY5MyAsuRLmyQUFMU8/c+i11m0=; h=X-UI-Sender-Class:Date:From:To:Subject; b=W+Pvc8W5ThHdJDLnfv+5B0KLRenzr2Ri7zDXLOHQ6unyy/ckKqdzT37w/lx8uNHPP eqqVy2NxhROvEV/gyep1G/OQF/bPjg2BQ2nu9rG9rMIFWC8/b2c9uhk2MslGMauepj zLRHxbdlCzVJlvQvtLn+iV0OLJTgOh0/t7t6tI9E= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from E15-2016.optimum.net ([72.89.170.172]) by mail.gmx.com (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MEV3C-1khux82Vz8-00G15X for ; Mon, 12 Oct 2020 16:26:40 +0200 Content-Disposition: inline X-Provags-ID: V03:K1:OZsUNsq2VtieMYs+o6ZZJ1PUHabt//1pU3g1MFenQrem7C9YbuB QkZfRYnjLTSX7gyaOo/PtvOCfJ00EMoXJ5zqTP7JEW6N/swUBM66TgakL4oef2pvi7r8RAz 4eJClzSNzc/dJsABv9+1dRcOlmWHJQB1y/MrChE5Sxdzv1lEA997xcoFfvnU1LIBtQtpCkl AGLKFDOiQTX7ldnlg+Raw== X-UI-Out-Filterresults: notjunk:1;V03:K0:GaCoZ7zg4yY=:5TP+YPKIohvcj3ACLheNgF lbcCOJND6xwA9DZAyQgkAgBbBITs/mHuP/SXN0E6NBhwtcq+/eymHiL+Qi6KmC3gM7DaBRyS5 hmQrxXGxf6XusjG27k+hzhIDkOxHbV4Dp+EhmRLCCdQo857O2FYxt1tV0GrZGIJNR63RGzmwQ +uRptnMjT+LMUsx6+5P8KugaHe0KIXgbrXlxpQg36nSJ6Xc/jS6iMmNtL8wcpyus/vhGHrvvc 33YvoRMpu6td4yZ0i3enwzv2b96nVwvKhC7PfME74EBdJu67Z657iEWtuiHAcQZJV2kWyZaGs u+T09IhxjDj5tdKqtFxzFJ8yE7IjRnDd7zYTTzr3BOIyVWFya+mVNq5eDrNz48PWdBHKZLWLe F77kq7UFGus5qxrMtAJALXcgt6xrjDAs91gzOiQVaWvtaq66+9B93vOtsvKDp6WUUDFVFDU8p ArW0pqdcNN0OdfjULIfN8NhWJtczMiXGahmzJ/+fCk0fzAm8K6tCWDC9iL/8oEpqtYUKJTFKW vGul8KlzOudGdGNFKBbgEGDcfprReBtfL4sOFdPXaWQk6ULjuqEwCLPEKXlamDEmHV6VhQtdB NtB+0aZp2bOP442wdzbg5tzV6Ey8s0S3cUZiogmFNaeHoRgZ6/RieSesXhWxuQUnPEIngQRhZ ToC9eGsy64E8OATSVKp3Ht2PLqfWT97x2LlNfKRQkeQB6b1k4gezI7VreG03rpgVMRxntQYwx 7LCOHH9xRGyhDcsznQpNpoGqYDtiWqmOfvvwQRRuDlhIhRa9IJ8ZIEruRMRpSiIvqyN+WpUH Received-SPF: pass client-ip=212.227.17.20; envelope-from=boruch_baum@gmx.com; helo=mout.gmx.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/12 09:35:13 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:190323 Archived-At: --aftfgvqp76s5o6ko Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable The attached patch takes a step to remove confusion surrounding two unfortunately named functions, fixes bugs in one of them, and makes them more user-friendly. If this is all acceptable, let me know and I'll add a NEWS entry. + dired-filename-at-point is moved from dired-x.el to a position alongside its sister function dired-file-name-at-point. + The code for dired-filename-at-point is simplified to an almost carbon copy of its sister function. + This also fixes bugs for cases of filenames with embedded spaces + This also suppresses errors, due to use of dired-get-filename with its arg NOERROR. + Both get a small style tweak to remove duplicated function calls to abbrev- or expand- file-name. + Both get aliases to make them distinguishable. A follow-up to the attached patch, if accepted, would be to refactor all the occurrences within dired.el / dired-x.el. It would probably be a good idea to also add a deprecation notice to the docstrings for the original names. I came across this while developing the diredc package I've been mentioning a lot lately, and presenting this as a separate patch removes it from being snagged as part of discussion about that other proposal. =2D- hkp://keys.gnupg.net CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0 --aftfgvqp76s5o6ko Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="dired-name-confusion.patch" Content-Transfer-Encoding: quoted-printable diff --git a/dired-x.el b/dired-x.el index b09ef90..d3b9dc9 100644 =2D-- 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 =2D-- 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 sug= gestion. --aftfgvqp76s5o6ko--