unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#66260: 29.0.92; project.el should support copying a file path relative to the project root
@ 2023-09-28 23:26 sbaugh
  2023-09-29  6:57 ` Juri Linkov
  2023-10-01 22:44 ` Dmitry Gutov
  0 siblings, 2 replies; 13+ messages in thread
From: sbaugh @ 2023-09-28 23:26 UTC (permalink / raw)
  To: 66260


When communicating with others, it is often useful to copy a file path
to the current file which is relative to the project root.  For example
I'd rather send someone the path lisp/progmodes/project.el than
~/src/emacs/trunk/lisp/progmodes/project.el.

project.el should have a way to copy this file path.

Almost good enough is:

 C-x p f       ;; project-find-file
 M-n	       ;; next-history-element
 C-k	       ;; kill-line

but with project--read-file-cpd-relative, if all the files in
project-files start with a common-parent-directory which is a
subdirectory of project-root, the resulting file path will not be
relative to the project-root but to the subdirectory.

Maybe the thing to do is just make project--read-file-cpd-relative use
project-root instead of calculating a common-parent-directory?  I would
be happy to make that patch if that's acceptable.  I think that's
probably the best option.

Alternatively, it might be cool if there was a variation on:

 C-x C-j     ;; dired-jump
 M-0	     ;; digit-argument
 w	     ;; dired-copy-filename-as-kill

(which copies an absolute path) to instead copy a project-root-relative
path.


In GNU Emacs 29.0.92 (build 68, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.16.0, Xaw3d scroll bars) of 2023-07-15 built on earth
Repository revision: 36d3460f9f6064c03fd88e0c969c8e4f4d645235
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12101008
System Description: NixOS 23.05 (Stoat)

Configured using:
 'configure --cache-file=config.cache --with-x-toolkit=lucid
 --with-tree-sitter --with-xinput2 CC=gcc PKG_CONFIG=pkg-config
 PKG_CONFIG_PATH=/nix/store/s3r15m8wbl4wqk4khqlf41ikryhjm1bi-file-5.44-dev/lib/pkgconfig:/nix/store/f9jbn419h46c78z1pi49yn9a8742b0ql-gnutls-3.8.0-dev/lib/pkgconfig:/nix/store/knq0pv08wm4dins7m4jh0n7cv7pjvdjr-nettle-3.9.1-dev/lib/pkgconfig:/nix/store/dy8p07vrrhdgpnl45xz9c0k0didbikdh-gmp-with-cxx-6.2.1-dev/lib/pkgconfig:/nix/store/6hkdabzyqhyq5ypq4c9b2cibr1d1zg1s-harfbuzz-7.3.0-dev/lib/pkgconfig:/nix/store/hyns944pqgblw4icskylvlpm5krmfvcr-graphite2-1.3.14-dev/lib/pkgconfig:/nix/store/08cdp9vgvy023ysfa2y01gzsm2jv6phx-jansson-2.14/lib/pkgconfig:/nix/store/nqlbk40lh7igs61l77dwgdkn8dc2akcm-libxml2-2.10.4-dev/lib/pkgconfig:/nix/store/b3axl73v3yvqqx7g47njqb5wzxvm280p-zlib-1.2.13-dev/lib/pkgconfig:/nix/store/3f2rc4inlcxmq11718qmz94v2rpybw70-ncurses-6.4-dev/lib/pkgconfig:/nix/store/bxy745kyb1fwhpfkiaaz3wgvpkpvwcpq-dbus-1.14.8-dev/lib/pkgconfig:/nix/store/9714v7c4cgpm4yqcyqk6n9xw9iq3a1bs-expat-2.5.0-dev/lib/pkgconfig:/nix/store/zzi7pcadidqh798yddxv6pwdbwpkikma-libselinux-3.3-dev/lib/pkgconfig:/nix/store/w14j7y5nl14vy4ikcivss35jmrqq3fxj-libotf-0.9.16-dev/lib/pkgconfig:/nix/store/arhk7hsch4scyv6m24fw03yq6wq5wbbx-m17n-lib-1.8.2/lib/pkgconfig:/nix/store/1jbbrny8xcjb68lb5m30cvxycfkyhvsv-sqlite-3.42.0-dev/lib/pkgconfig:/nix/store/5vx779yqkxaysv48gicwlgv0ippbrhc4-systemd-253.5-dev/lib/pkgconfig:/nix/store/5vx779yqkxaysv48gicwlgv0ippbrhc4-systemd-253.5-dev/share/pkgconfig:/nix/store/djifahvk3qp06ssqxv6gy1ixdnnypr9s-tree-sitter-0.20.8/lib/pkgconfig:/nix/store/74aasy1d2r5y27zn68cs1rxwy1llzn05-libwebp-1.3.0/lib/pkgconfig:/nix/store/8sk7bp89iwb4gw96fq6xakb6lcy2x52n-Xaw3d-1.6.3/lib/pkgconfig:/nix/store/ppvb3ha8148am3ajnzxnm6i3ri38c01n-libXmu-1.1.3-dev/lib/pkgconfig:/nix/store/jyxf8cjbj3nzh00x48nfram79i63chdi-libX11-1.8.6-dev/lib/pkgconfig:/nix/store/zk9v0nr5zdfi1ybkhcfifmxsng7hfl23-xorgproto-2021.5/share/pkgconfig:/nix/store/3q1k18v8aa6mxs538bha4ry0mp3m321l-libxcb-1.14-dev/lib/pkgconfig:/nix/store/hcscz68zvfk1skyb25wrnha959f6hhrc-libXt-1.2.1-dev/lib/pkgconfig:/nix/store/kl55wj6qc3v481jsgvzm5w2csnhm84zf-libSM-1.2.3-dev/lib/pkgconfig:/nix/store/s3f67kvsn55rxp2rc98xv0hkq364yci1-libICE-1.0.10-dev/lib/pkgconfig:/nix/store/rsw4ri8025jgln8vpsrmg82bzgbcw3zr-cairo-1.16.0-dev/lib/pkgconfig:/nix/store/jir0rqbcy0d9qr9kf5cwf2yphql4ykyw-fontconfig-2.14.2-dev/lib/pkgconfig:/nix/store/n2g3xblaz1k4civv1z6hhm1nsmp3m17p-freetype-2.13.0-dev/lib/pkgconfig:/nix/store/isbmyzm2shmp0wsjr4cy45v2i58h2zvw-bzip2-1.0.8-dev/lib/pkgconfig:/nix/store/bl2qwy78jr2sqm260imgxmd5dzhjqvag-brotli-1.0.9-dev/lib/pkgconfig:/nix/store/z96jh9ag5b3565lwwb5chjb9bfp5i2qv-libpng-apng-1.6.39-dev/lib/pkgconfig:/nix/store/jjd4z18grhky6lh8n463v648nnf5628b-pixman-0.42.2/lib/pkgconfig:/nix/store/qd14wrazwcspjv3q65vgh35pl7b8nifq-libXext-1.3.4-dev/lib/pkgconfig:/nix/store/gj8i21xx87ip9b971j2d1m0rmrzyhbir-libXau-1.0.9-dev/lib/pkgconfig:/nix/store/4gpinwwdqhi927xkrfpr1hvdd56baxgk-libXrender-0.9.10-dev/lib/pkgconfig:/nix/store/d1jbygs6hcn6dysk706i9zf07yd18wmr-xcb-util-0.4.1-dev/lib/pkgconfig:/nix/store/hdc4ika0mb1cv0cf6dchwxbr004rc50i-glib-2.76.3-dev/lib/pkgconfig:/nix/store/wxyh848a6xcqy2v8727vcwspri53pqwi-libffi-3.4.4-dev/lib/pkgconfig:/nix/store/42jx72681qzliic0xsjhvx24cil2gapk-libGL-1.6.0-dev/lib/pkgconfig:/nix/store/b9lmdkxpvgkj6zc956fvhshzisqpi767-libglvnd-1.6.0-dev/lib/pkgconfig:/nix/store/gff29sbhg1gcw969mpm5rb693kj5v18w-libXaw-1.0.14-dev/lib/pkgconfig:/nix/store/776xijk8rsb1b4c0dsxwq0k82bvm7mm9-libXpm-3.5.15-dev/lib/pkgconfig:/nix/store/qizdmm43xi65mdngal8bpbpqcdc8290d-libjpeg-turbo-2.1.5.1-dev/lib/pkgconfig:/nix/store/db7ix62fx4nvr9j1fjdvnznl2npff4pr-librsvg-2.55.1-dev/lib/pkgconfig:/nix/store/q0hg0951w1dv9y40m9ggln8phwil6lxc-gdk-pixbuf-2.42.10-dev/lib/pkgconfig:/nix/store/34rr5nvgljsc4bi3mxjxg8abmjr1f7hn-libtiff-4.5.0-dev/lib/pkgconfig:/nix/store/zwkr4kjcjs213pw9mhzi46bzlw6qwxzq-libdeflate-1.18/lib/pkgconfig:/nix/store/6na552yzwml88j8g5vqf5h9ir3vw8myi-xz-5.4.3-dev/lib/pkgconfig
 CXX=g++'

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG JSON
LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY INOTIFY
PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS
TREE_SITTER WEBP X11 XAW3D XDBE XIM XPM LUCID ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: notmuch-search

Minor modes in effect:
  hl-line-mode: t
  envrc-global-mode: t
  envrc-mode: t
  global-git-commit-mode: t
  magit-auto-revert-mode: t
  shell-dirtrack-mode: t
  server-mode: t
  windmove-mode: t
  pixel-scroll-precision-mode: t
  savehist-mode: t
  save-place-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tab-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  context-menu-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  buffer-read-only: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/home/sbaugh/.emacs.d/elpa/transient-0.3.7/transient hides /home/sbaugh/src/emacs/emacs-29/lisp/transient

Features:
(shadow emacsbug wdired tramp-archive tramp-gvfs nov recentf tree-widget
magit-bookmark bookmark esxml-query arc-mode archive-mode dired-aux
dired-x textsec uni-scripts idna-mapping ucs-normalize uni-confusable
textsec-check sort mail-extr em-unix em-term term disp-table ehelp
em-script em-prompt em-ls em-hist em-pred em-glob em-extpipe em-cmpl
em-dirs esh-var em-basic em-banner em-alias esh-mode eshell esh-cmd
esh-ext esh-opt esh-proc esh-io esh-arg esh-module esh-groups esh-util
whitespace log-view pcmpl-unix erc-pcomplete erc-goodies erc erc-backend
erc-networks erc-common erc-compat erc-loaddefs debug backtrace
tramp-cmds cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align
cc-engine cc-vars cc-defs pulse color xref bug-reference completion
cl-print shortdoc help-fns radix-tree pcmpl-linux tramp-cache time-stamp
tramp-sh tramp tramp-loaddefs trampver tramp-integration tramp-compat
mm-archive vc-git package-vc vc vc-dispatcher lisp-mnt network-stream
url-cache url-http url-auth url-gw nsm display-line-numbers org-element
org-persist org-id org-refile avl-tree generator oc-basic ol-eww eww xdg
url-queue mm-url ol-rmail ol-mhe ol-irc ol-info ol-gnus nnselect
gnus-art mm-uu mml2015 gnus-sum shr pixel-fill kinsoku url-file svg dom
gnus-group gnus-undo gnus-start gnus-dbus dbus xml gnus-cloud nnimap
nnmail mail-source utf7 nnoo parse-time gnus-spec gnus-int gnus-range
gnus-win gnus nnheader range ol-docview doc-view jka-compr image-mode
exif ol-bibtex bibtex iso8601 ol-bbdb ol-w3m ol-doi org-link-doi org
org-macro org-pcomplete org-list org-footnote org-faces org-entities
noutline outline ob-python python compat ob ob-tangle org-src ob-ref
ob-lob ob-table ob-exp ob-comint ob-emacs-lisp ob-core ob-eval org-cycle
org-table ol org-fold org-fold-core org-keys oc org-loaddefs find-func
org-version org-compat org-macs ffap mule-util misearch multi-isearch
notmuch notmuch-tree notmuch-jump notmuch-hello notmuch-show
notmuch-print notmuch-crypto notmuch-mua notmuch-message notmuch-draft
notmuch-maildir-fcc notmuch-address notmuch-company notmuch-parser
notmuch-wash coolj goto-addr icalendar diary-lib diary-loaddefs cal-menu
calendar cal-loaddefs notmuch-tag notmuch-lib notmuch-compat hl-line
mm-view mml-smime smime dig sh-script smie treesit executable project
files-x face-remap exwm-randr xcb-randr exwm exwm-input xcb-keysyms
xcb-xkb exwm-manage exwm-floating xcb-cursor xcb-render exwm-layout
exwm-workspace exwm-core xcb-ewmh xcb-icccm xcb xcb-xproto xcb-types
xcb-debug lui-autopaste circe advice lui-irc-colors irc gnutls lcs
lui-logging lui-format lui tracking shorten thingatpt flyspell ispell
circe-compat agda2 envrc inheritenv page-ext magit-extras
magit-submodule magit-obsolete magit-blame magit-stash magit-reflog
magit-bisect magit-push magit-pull magit-fetch magit-clone magit-remote
magit-commit magit-sequence magit-notes magit-worktree magit-tag
magit-merge magit-branch magit-reset magit-files magit-refs magit-status
magit magit-repos magit-apply magit-wip magit-log which-func imenu
magit-diff smerge-mode diff diff-mode git-commit rx log-edit message
sendmail yank-media puny dired desktop frameset dired-loaddefs rfc822
mml mml-sec epa derived epg rfc6068 epg-config gnus-util
text-property-search time-date mm-decode mm-bodies mm-encode mail-parse
rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr mailabbrev
mail-utils gmm-utils mailheader pcvs-util add-log magit-core
magit-autorevert autorevert filenotify magit-margin magit-transient
magit-process with-editor shell pcomplete comint ansi-osc server
ansi-color magit-mode transient cl-extra edmacro kmacro help-mode
format-spec magit-git magit-section magit-utils crm dash windmove
easy-mmode pixel-scroll cua-base ring modus-vivendi-theme modus-themes
pcase cus-edit pp cus-load icons wid-edit savehist saveplace finder-inf
ace-window-autoloads auctex-autoloads tex-site avy-autoloads
circe-autoloads corfu-autoloads compat-autoloads csv-mode-autoloads
cyberpunk-theme-autoloads debbugs-autoloads eat-autoloads
envrc-autoloads exwm-autoloads ggtags-autoloads
graphviz-dot-mode-autoloads htmlize-autoloads inheritenv-autoloads
magit-autoloads git-commit-autoloads markdown-mode-autoloads
mastodon-autoloads mentor-autoloads async-autoloads mpv-autoloads
nix-mode-autoloads magit-section-autoloads dash-autoloads
notmuch-autoloads persist-autoloads request-autoloads
rust-mode-autoloads transient-autoloads url-scgi-autoloads
vundo-autoloads which-key-autoloads info with-editor-autoloads
xelb-autoloads xml-rpc-autoloads package browse-url url url-proxy
url-privacy url-expand url-methods url-history url-cookie
generate-lisp-file url-domsuf url-util mailcap url-handlers url-parse
auth-source cl-seq eieio eieio-core cl-macs password-cache json subr-x
map byte-opt gv bytecomp byte-compile url-vars cl-loaddefs cl-lib rmc
iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads dbusbind inotify dynamic-setting system-font-setting
font-render-setting cairo x-toolkit x multi-tty make-network-process
emacs)

Memory information:
((conses 16 1626286 137327)
 (symbols 48 54331 39)
 (strings 32 272934 16451)
 (string-bytes 1 8527712)
 (vectors 16 136502)
 (vector-slots 8 2511205 204833)
 (floats 8 581 399)
 (intervals 56 122255 2589)
 (buffers 984 43))





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#66260: 29.0.92; project.el should support copying a file path relative to the project root
  2023-09-28 23:26 bug#66260: 29.0.92; project.el should support copying a file path relative to the project root sbaugh
@ 2023-09-29  6:57 ` Juri Linkov
  2023-09-30 13:50   ` sbaugh
  2023-10-01 22:44 ` Dmitry Gutov
  1 sibling, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2023-09-29  6:57 UTC (permalink / raw)
  To: sbaugh; +Cc: 66260

> When communicating with others, it is often useful to copy a file path
> to the current file which is relative to the project root.  For example
> I'd rather send someone the path lisp/progmodes/project.el than
> ~/src/emacs/trunk/lisp/progmodes/project.el.

I have the same problem.  Often for a project directory I give
a name of the current branch, but later after switching branches
sending an absolute file path with an obsolete directory name
would be very confusing.  So every time need to spend too much time
manually removing the prefix.

> project.el should have a way to copy this file path.
>
> Almost good enough is:
>
>  C-x p f       ;; project-find-file
>  M-n	       ;; next-history-element
>  C-k	       ;; kill-line
>
> but with project--read-file-cpd-relative, if all the files in
> project-files start with a common-parent-directory which is a
> subdirectory of project-root, the resulting file path will not be
> relative to the project-root but to the subdirectory.
>
> Maybe the thing to do is just make project--read-file-cpd-relative use
> project-root instead of calculating a common-parent-directory?  I would
> be happy to make that patch if that's acceptable.  I think that's
> probably the best option.

Sorry, I have no opinion about the option above, because I always use
dired-copy-filename-as-kill with the zero prefix argument:

> Alternatively, it might be cool if there was a variation on:
>
>  C-x C-j     ;; dired-jump
>  M-0	     ;; digit-argument
>  w	     ;; dired-copy-filename-as-kill
>
> (which copies an absolute path) to instead copy a project-root-relative
> path.

Sometimes an absolute path is needed too even in project directories.
Maybe it's possible to find a new prefix argument to copy
a project-root-relative path like 'C-u C-u w'?





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#66260: 29.0.92; project.el should support copying a file path relative to the project root
  2023-09-29  6:57 ` Juri Linkov
@ 2023-09-30 13:50   ` sbaugh
  2023-09-30 14:47     ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 13+ messages in thread
From: sbaugh @ 2023-09-30 13:50 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 66260

[-- Attachment #1: Type: text/plain, Size: 373 bytes --]

Juri Linkov <juri@linkov.net> writes:
> Sometimes an absolute path is needed too even in project directories.
> Maybe it's possible to find a new prefix argument to copy
> a project-root-relative path like 'C-u C-u w'?

I initially considered M-1 w, but that loses the ability to mark files
and then only copy one of them.  C-u C-u seems good.

Here's the implementation.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Project-support-in-dired-copy-filename-as-kill.patch --]
[-- Type: text/x-patch, Size: 2220 bytes --]

From 95bd0a8775284dc59119198b02fcc64b904c4d7f Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@catern.com>
Date: Sat, 30 Sep 2023 09:49:03 -0400
Subject: [PATCH] Project support in dired-copy-filename-as-kill

It is often useful to get a filename relative to project-root; now it
is easier.

* lisp/dired.el (dired-get-filename): Support 'project.
(dired-copy-filename-as-kill): Make C-u C-u pass 'project.
---
 lisp/dired.el | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lisp/dired.el b/lisp/dired.el
index cc8c74839b9..cc2cf24fac2 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -3016,6 +3016,12 @@ dired-get-filename
 	(if (and handler (not (get handler 'safe-magic)))
 	    (concat "/:" file)
 	  file)))
+     ((eq localp 'project)
+      (if-let ((project (project-current nil (dired-current-directory))))
+          (file-relative-name
+           (concat (dired-current-directory) file)
+           (project-root project))
+        (concat (dired-current-directory t) file)))
      (t
       (concat (dired-current-directory localp) file)))))
 
@@ -3240,6 +3246,7 @@ dired-copy-filename-as-kill
 With a zero prefix arg, use the absolute file name of each marked file.
 With \\[universal-argument], use the file name relative to the Dired buffer's
 `default-directory'.  (This still may contain slashes if in a subdirectory.)
+With \\[universal-argument] \\[universal-argument], use the file name relative to `project-root'.
 
 If on a subdir headerline, use absolute subdirname instead;
 prefix arg and marked files are ignored in this case.
@@ -3251,8 +3258,10 @@ dired-copy-filename-as-kill
               (if arg
                   (cond ((zerop (prefix-numeric-value arg))
                          (dired-get-marked-files))
-                        ((consp arg)
+                        ((and (consp arg) (= 4 (prefix-numeric-value arg)))
                          (dired-get-marked-files t))
+                        ((and (consp arg) (>= 16 (prefix-numeric-value arg)))
+                         (dired-get-marked-files 'project))
                         (t
                          (dired-get-marked-files
 			  'no-dir (prefix-numeric-value arg))))
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* bug#66260: 29.0.92; project.el should support copying a file path relative to the project root
  2023-09-30 13:50   ` sbaugh
@ 2023-09-30 14:47     ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-09-30 15:17       ` sbaugh
  0 siblings, 1 reply; 13+ messages in thread
From: Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-09-30 14:47 UTC (permalink / raw)
  To: sbaugh; +Cc: 66260, Juri Linkov

Hi,

sbaugh@catern.com writes:

> Juri Linkov <juri@linkov.net> writes:
>> Sometimes an absolute path is needed too even in project directories.
>> Maybe it's possible to find a new prefix argument to copy
>> a project-root-relative path like 'C-u C-u w'?
>
> I initially considered M-1 w, but that loses the ability to mark files
> and then only copy one of them.  C-u C-u seems good.

FWIW I think a separate command and binding would be preferable, namely
`C-x p w`.  That'd leave `w` intact and clearly indicate the
project-related nature of the (new) command, so it's arguably more
intuitive than `C-u C-u w`.  We could also have that binding in
non-Dired buffers, and have it operate on the visited file.





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#66260: 29.0.92; project.el should support copying a file path relative to the project root
  2023-09-30 14:47     ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-09-30 15:17       ` sbaugh
  0 siblings, 0 replies; 13+ messages in thread
From: sbaugh @ 2023-09-30 15:17 UTC (permalink / raw)
  To: Eshel Yaron; +Cc: 66260, Juri Linkov

Eshel Yaron <me@eshelyaron.com> writes:
> Hi,
>
> sbaugh@catern.com writes:
>
>> Juri Linkov <juri@linkov.net> writes:
>>> Sometimes an absolute path is needed too even in project directories.
>>> Maybe it's possible to find a new prefix argument to copy
>>> a project-root-relative path like 'C-u C-u w'?
>>
>> I initially considered M-1 w, but that loses the ability to mark files
>> and then only copy one of them.  C-u C-u seems good.
>
> FWIW I think a separate command and binding would be preferable, namely
> `C-x p w`.  That'd leave `w` intact and clearly indicate the
> project-related nature of the (new) command, so it's arguably more
> intuitive than `C-u C-u w`.  We could also have that binding in
> non-Dired buffers, and have it operate on the visited file.

I don't think there's any need to avoid modifying w, so even if we added
this other C-x p w command, I would still like C-u C-u w to work.  It's
useful when navigating a project tree in dired.





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#66260: 29.0.92; project.el should support copying a file path relative to the project root
  2023-09-28 23:26 bug#66260: 29.0.92; project.el should support copying a file path relative to the project root sbaugh
  2023-09-29  6:57 ` Juri Linkov
@ 2023-10-01 22:44 ` Dmitry Gutov
  2023-10-02  5:57   ` Eli Zaretskii
  2023-10-21 13:13   ` sbaugh
  1 sibling, 2 replies; 13+ messages in thread
From: Dmitry Gutov @ 2023-10-01 22:44 UTC (permalink / raw)
  To: sbaugh, 66260

On 29/09/2023 02:26, sbaugh@catern.com wrote:
> When communicating with others, it is often useful to copy a file path
> to the current file which is relative to the project root.  For example
> I'd rather send someone the path lisp/progmodes/project.el than
> ~/src/emacs/trunk/lisp/progmodes/project.el.
> 
> project.el should have a way to copy this file path.
> 
> Almost good enough is:
> 
>   C-x p f       ;; project-find-file
>   M-n	       ;; next-history-element
>   C-k	       ;; kill-line
> 
> but with project--read-file-cpd-relative, if all the files in
> project-files start with a common-parent-directory which is a
> subdirectory of project-root, the resulting file path will not be
> relative to the project-root but to the subdirectory.

A problem with modifying the above function's behavior like that is that 
sometimes it is passed a wider range of file names, where not all of 
them are inside the project root (M-x project-or-external-find-file).

> Maybe the thing to do is just make project--read-file-cpd-relative use
> project-root instead of calculating a common-parent-directory?  I would
> be happy to make that patch if that's acceptable.  I think that's
> probably the best option.
> 
> Alternatively, it might be cool if there was a variation on:
> 
>   C-x C-j     ;; dired-jump
>   M-0	     ;; digit-argument
>   w	     ;; dired-copy-filename-as-kill
> 
> (which copies an absolute path) to instead copy a project-root-relative
> path.

This is unfortunately less discoverable, but sounds good otherwise.

Regarding the potential binding (discussed further downthread), I have 
no opinion: copying the relative name doesn't happen too often for me, 
and when it does, I can usually do that from the VC-Dir buffer (where 
the file in question would usually be 'edited'). Should we add 'w' to 
vc-dir-mode too?

'C-x p w' does make sense as such, but it would be unfortunate if we 
find a more important command later which fits the 'w' mnemonics. Maybe 
'C-x p W' would be a more conservative choice.





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#66260: 29.0.92; project.el should support copying a file path relative to the project root
  2023-10-01 22:44 ` Dmitry Gutov
@ 2023-10-02  5:57   ` Eli Zaretskii
  2023-10-02  6:53     ` Juri Linkov
  2023-10-02 11:13     ` Rudolf Adamkovič via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-10-21 13:13   ` sbaugh
  1 sibling, 2 replies; 13+ messages in thread
From: Eli Zaretskii @ 2023-10-02  5:57 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: sbaugh, 66260

> Date: Mon, 2 Oct 2023 01:44:38 +0300
> From: Dmitry Gutov <dmitry@gutov.dev>
> 
> 'C-x p w' does make sense as such, but it would be unfortunate if we 
> find a more important command later which fits the 'w' mnemonics. Maybe 
> 'C-x p W' would be a more conservative choice.

Or even "C-x p C-w".





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#66260: 29.0.92; project.el should support copying a file path relative to the project root
  2023-10-02  5:57   ` Eli Zaretskii
@ 2023-10-02  6:53     ` Juri Linkov
  2023-10-02 11:46       ` Dmitry Gutov
  2023-10-02 11:13     ` Rudolf Adamkovič via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2023-10-02  6:53 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Dmitry Gutov, 66260, sbaugh

>> 'C-x p w' does make sense as such, but it would be unfortunate if we
>> find a more important command later which fits the 'w' mnemonics. Maybe
>> 'C-x p W' would be a more conservative choice.
>
> Or even "C-x p C-w".

Or 'C-x p C-c' like 'c' in Info-mode-map for Info-copy-current-node-name.





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#66260: 29.0.92; project.el should support copying a file path relative to the project root
  2023-10-02  5:57   ` Eli Zaretskii
  2023-10-02  6:53     ` Juri Linkov
@ 2023-10-02 11:13     ` Rudolf Adamkovič via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 0 replies; 13+ messages in thread
From: Rudolf Adamkovič via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-10-02 11:13 UTC (permalink / raw)
  To: Eli Zaretskii, Dmitry Gutov; +Cc: sbaugh, 66260

Eli Zaretskii <eliz@gnu.org> writes:

> Or even "C-x p C-w".

Why not 'C-x p M-w' to match 'M-w (kill-ring-save)' instead?

P.S. It would also match Vertico, where 'M-w' already saves the relative
path of the currently selected file after 'C-x p f'.

Rudy
-- 
"If you're thinking without writing, you only think you're thinking."
--- Leslie Lamport

Rudolf Adamkovič <salutis@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#66260: 29.0.92; project.el should support copying a file path relative to the project root
  2023-10-02  6:53     ` Juri Linkov
@ 2023-10-02 11:46       ` Dmitry Gutov
  2023-10-03 20:49         ` sbaugh
  0 siblings, 1 reply; 13+ messages in thread
From: Dmitry Gutov @ 2023-10-02 11:46 UTC (permalink / raw)
  To: Juri Linkov, Eli Zaretskii; +Cc: sbaugh, 66260

On 02/10/2023 09:53, Juri Linkov wrote:
>>> 'C-x p w' does make sense as such, but it would be unfortunate if we
>>> find a more important command later which fits the 'w' mnemonics. Maybe
>>> 'C-x p W' would be a more conservative choice.
>> Or even "C-x p C-w".
> Or 'C-x p C-c' like 'c' in Info-mode-map for Info-copy-current-node-name.

That one was probably made from the CUA user's standpoint.

I sympathize, but even Info-mode-map has a 'w' binding (thanks to you, 
looks like).

So C-w or M-w seem like a better choice for the default bindings.





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#66260: 29.0.92; project.el should support copying a file path relative to the project root
  2023-10-02 11:46       ` Dmitry Gutov
@ 2023-10-03 20:49         ` sbaugh
  2023-10-03 21:17           ` Dmitry Gutov
  0 siblings, 1 reply; 13+ messages in thread
From: sbaugh @ 2023-10-03 20:49 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Eli Zaretskii, 66260, Juri Linkov

Dmitry Gutov <dmitry@gutov.dev> writes:
> On 02/10/2023 09:53, Juri Linkov wrote:
>>>> 'C-x p w' does make sense as such, but it would be unfortunate if we
>>>> find a more important command later which fits the 'w' mnemonics. Maybe
>>>> 'C-x p W' would be a more conservative choice.
>>> Or even "C-x p C-w".
>> Or 'C-x p C-c' like 'c' in Info-mode-map for Info-copy-current-node-name.
>
> That one was probably made from the CUA user's standpoint.
>
> I sympathize, but even Info-mode-map has a 'w' binding (thanks to you,
> looks like).
>
> So C-w or M-w seem like a better choice for the default bindings.

I don't think C-x p w is quite necessary.  But even if it was, I think
there's a good other candidate for what it should do: copy the project
root.  That would also be pretty useful.

For example, I often move a patch between two projects by first
rendering it in one project (with C-x v D), entering M-x cd
other/project/root in the *vc-diff* buffer, and then applying the diff.
If there was a quick way to get other/project/root, it would speed this
up.

Sometimes I also run shell commands which need the project root.

I can always do C-x p D then copy the file name of that buffer, but
that's about as painful as C-x C-j C-u C-u w, so if C-x C-j C-u C-u w is
too cumbersome then it seems to me that so is C-x p D and copy.





^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#66260: 29.0.92; project.el should support copying a file path relative to the project root
  2023-10-03 20:49         ` sbaugh
@ 2023-10-03 21:17           ` Dmitry Gutov
  0 siblings, 0 replies; 13+ messages in thread
From: Dmitry Gutov @ 2023-10-03 21:17 UTC (permalink / raw)
  To: sbaugh; +Cc: Eli Zaretskii, 66260, Juri Linkov

On 03/10/2023 23:49, sbaugh@catern.com wrote:
> Dmitry Gutov <dmitry@gutov.dev> writes:
>> On 02/10/2023 09:53, Juri Linkov wrote:
>>>>> 'C-x p w' does make sense as such, but it would be unfortunate if we
>>>>> find a more important command later which fits the 'w' mnemonics. Maybe
>>>>> 'C-x p W' would be a more conservative choice.
>>>> Or even "C-x p C-w".
>>> Or 'C-x p C-c' like 'c' in Info-mode-map for Info-copy-current-node-name.
>>
>> That one was probably made from the CUA user's standpoint.
>>
>> I sympathize, but even Info-mode-map has a 'w' binding (thanks to you,
>> looks like).
>>
>> So C-w or M-w seem like a better choice for the default bindings.
> 
> I don't think C-x p w is quite necessary.  But even if it was, I think
> there's a good other candidate for what it should do: copy the project
> root.  That would also be pretty useful.

Not necessary, but if more than one user likes that, I think we can 
dedicate the C-w binding for it.

> For example, I often move a patch between two projects by first
> rendering it in one project (with C-x v D), entering M-x cd
> other/project/root in the *vc-diff* buffer, and then applying the diff.
> If there was a quick way to get other/project/root, it would speed this
> up.

Depending on how often you do either thing, 'C-x p C-w' could copy the 
relative file name, and 'c-u C-x p C-w' could copy the root.

Or the latter action could be moved to 'C-x p C-S-w', for example (by 
analogy with C-x v D'.

> Sometimes I also run shell commands which need the project root.
> 
> I can always do C-x p D then copy the file name of that buffer, but
> that's about as painful as C-x C-j C-u C-u w, so if C-x C-j C-u C-u w is
> too cumbersome then it seems to me that so is C-x p D and copy.






^ permalink raw reply	[flat|nested] 13+ messages in thread

* bug#66260: 29.0.92; project.el should support copying a file path relative to the project root
  2023-10-01 22:44 ` Dmitry Gutov
  2023-10-02  5:57   ` Eli Zaretskii
@ 2023-10-21 13:13   ` sbaugh
  1 sibling, 0 replies; 13+ messages in thread
From: sbaugh @ 2023-10-21 13:13 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 66260

[-- Attachment #1: Type: text/plain, Size: 1221 bytes --]

Dmitry Gutov <dmitry@gutov.dev> writes:
> On 29/09/2023 02:26, sbaugh@catern.com wrote:
>> When communicating with others, it is often useful to copy a file path
>> to the current file which is relative to the project root.  For example
>> I'd rather send someone the path lisp/progmodes/project.el than
>> ~/src/emacs/trunk/lisp/progmodes/project.el.
>> project.el should have a way to copy this file path.
>> Almost good enough is:
>>   C-x p f       ;; project-find-file
>>   M-n	       ;; next-history-element
>>   C-k	       ;; kill-line
>> but with project--read-file-cpd-relative, if all the files in
>> project-files start with a common-parent-directory which is a
>> subdirectory of project-root, the resulting file path will not be
>> relative to the project-root but to the subdirectory.
>
> A problem with modifying the above function's behavior like that is
> that sometimes it is passed a wider range of file names, where not all
> of them are inside the project root (M-x
> project-or-external-find-file).

Oh, what if we just *check* if the common-parent-directory is below the
project root, and in that case use the project root instead?  That
elegantly resolves this without breaking that.

Like this:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Use-project-root-in-project-find-file-if-all-files-a.patch --]
[-- Type: text/x-patch, Size: 2083 bytes --]

From c5b2e49cc8117e063d9e16a9072eb07ddff8aaa5 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@catern.com>
Date: Sat, 21 Oct 2023 09:11:52 -0400
Subject: [PATCH] Use project-root in project-find-file if all files are below
 it

project-files can return a list of files all of whom are in a
subdirectory of project-root.  We should still use project-root in
project--read-file-cpd-relative in that case, for several reasons:

- Now M-n will always bring up the full path of the current file for
  copying

- Now if the user wants to manually type in a path starting at the
  root, they can.

* lisp/progmodes/project.el (project--read-file-cpd-relative):
Always use project-root if all files are below that. (bug#66260)
---
 lisp/progmodes/project.el | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 0d6539113cc..dcd1cab4f96 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1117,9 +1117,16 @@ project--read-file-cpd-relative
 MB-DEFAULT is used as part of \"future history\", to be inserted
 by the user at will."
   (let* ((common-parent-directory
-          (let ((common-prefix (try-completion "" all-files)))
-            (if (> (length common-prefix) 0)
-                (file-name-directory common-prefix))))
+          (let* ((common-prefix (try-completion "" all-files))
+                 (root (project-root (project-current)))
+                 (expand-root (expand-file-name root))
+                 (abbrev-root (abbreviate-file-name root)))
+            (cond
+             ;; We try use the project-root even if all the files have
+             ;; a c-p-d below the project-root.
+             ((string-prefix-p expand-root common-prefix) expand-root)
+             ((string-prefix-p abbrev-root common-prefix) abbrev-root)
+             ((> (length common-prefix) 0) (file-name-directory common-prefix)))))
          (cpd-length (length common-parent-directory))
          (prompt (if (zerop cpd-length)
                      prompt
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-10-21 13:13 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-28 23:26 bug#66260: 29.0.92; project.el should support copying a file path relative to the project root sbaugh
2023-09-29  6:57 ` Juri Linkov
2023-09-30 13:50   ` sbaugh
2023-09-30 14:47     ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-30 15:17       ` sbaugh
2023-10-01 22:44 ` Dmitry Gutov
2023-10-02  5:57   ` Eli Zaretskii
2023-10-02  6:53     ` Juri Linkov
2023-10-02 11:46       ` Dmitry Gutov
2023-10-03 20:49         ` sbaugh
2023-10-03 21:17           ` Dmitry Gutov
2023-10-02 11:13     ` Rudolf Adamkovič via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-21 13:13   ` sbaugh

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).