Follow

Because it is so useful - here is another reminder that you can actually rename files by edit operations in dired buffers. Press C-x C-q to enter 'wdired' mode and edit the filename, link and mode to your hearts delight. C-c C-c or C-x C-s will commit the changes to disk.

It goes without saying that a 'query-replace' operation will limit itself to the filenames. So e.g. replacing spaces by underscores in a whole directory is straight forward.

· · Web · 1 · 1 · 3

@dzu didn't realize it had a standard key binding, nice. I have it bound to E.

Is the `query-replace' restriction from wdired? I don't see why one shouldn't search for "r--" and replace it with "r-x", or want to query "/projects/" and replace it with "/src/" in links, as examples. Perhaps I'm thinking about this the wrong way? I usually personally just do simple file renaming with wdired.

@ryuslash Very good question indeed! I just saw that it works like this in my recent Emacs, but of course your question is totally valid.

It seems this a recent addition in wdired.el:

(defcustom wdired-search-replace-filenames t
"Non-nil to search and replace in file names only."
:version "29.1"
:type 'boolean)

So this feature is not even released yet. If you don't run any recent Emacs, then this is something to look forward to 😀

Thanks for pressuring me into correcting that.

@dzu ah cool! I'll have to look at that. I wonder if that's the behavior that previous versions have?

Thanks for looking at it! I just noticed you said "it goes without saying" and I had no clue why that would be ^_^;

@ryuslash Yeah, the "goes without saying" was probably exaggerated. When I recently needed comparable functionality I remembered that wdired should be able to solve my problem, and so I looked up my notes on it. While doing some manual editing I thought "hm, I wonder how query-replace is handled. It would be so extra cool if it limits itself to the filenames. Ok, that's probably not a valid expectation".

But to my total surprise it just did it when I then tried it 😂

@dzu ah! That completely changes the meaning of what you said for me. I understand where that comes from, yes of course Emacs already can do the thing you wanted it to do :D

@ryuslash Again a very good question. It seems that the code changed recently and that the new defcustom tries to "pull in" the functionality previously contained in dired-aux. There were (and still are) separate find functions in dired to limit to filenames: dired-isearch-filenames and dired-isearch-filenames-regexp. The new defcustom exposes this functionality through standard commands.

@ryuslash What I mean by this is that regular 'isearch-forward' (usually bound to C-s) will also limit itself to filenames governed by the defcustom. This exposes this nice functionality without me having to remember that there are different commands for it.

@ryuslash And by the way, I only noticed the standard key binding through the menu bar. Looking at the sources the menu item has been there for a while (2004) but I am not sure about the binding. So probably you are not using menu-bar-mode? (To be honest, I didn't for a very long time but enabled it again recently to find seldom used stuff).

@dzu you're right, disabling the menu bar, tool bar, and scroll bar is usually one of the first things in my Emacs init.

I think they're really cool, but I just have no use for them myself. I still one day would like to help someone who isn't keyboard-oriented like me use Emacs by customizing the menu bar and tool bar. (And mouse actions in general)

#emacs

Sign in to participate in the conversation
hostsharing.coop | Hostsharer im Fediverse

hostsharing.coop ist die Mastodon-Instanz für Mitglieder der Hostsharing eG. Sie wird seit 2018 von der Hosting-Genossenschaft betrieben.