The command ido-find-file offers the option to restrict the completion list using a filter. For example, one may input .cpp, press C-SPC et voila, the completion list is restricted to files with .cpp.
However, sometimes it is useful to restrict the list to directories in the first steps of navigation, e.g. when one is navigating to a file, residing in a subdirectory of unknown name, which is located within a directory with a lot of ordinary files.
Is there some built-in functionality for restricting ido to accept only directories in the current step (current step is either delimited by a) calling an un-restrict function, or b) [also the better solution] by an actual naviagtional command, i.e. descending/ascending in the directory tree level)? Or, if not, can someone write a function to do just that?
This functionality is already present in form of ido-dired.
UPD:
Two-stage find-file is as easy as you could imagine:
(defun find-file-2 ()
(interactive)
(ido-dired)
(ido-find-file))
Related
How can I search files just like with / command but recursively scanning subfolders?
Or maybe there are other approaches to get a list of files that match some pattern in the current folder including all subfolders.
:find command
There is :fin[d] command for that. Internally it invokes find utility (this is configurable via 'findprg' option), so you can do everything find is capable of. That said, in most cases the simple form of the command suffices:
:find *.sh
Note that by default argument is treated as regular file pattern (-name option of find), which is different from regular expressions accepted by /. For searching via regexp, use:
:find -regex '.*_.*'
If you want to scan only specific subfolders, just select them before running the command and search will be limited only to those directories.
:find command brings up a menu with search results. If you want to process them like regular files (e.g. delete, copy, move), hit b to change list representation.
Alternative that uses /
Alternatively you can populate current view with list of files in all subdirectories with command like (see %u):
:!find%u
and then use /, although this might be less efficient.
What's the best way to associate file extensions with my own customizations? For example, when I open a .py file the frame would be bigger and split into 2 windows, but when a .tex file is opened the frame would be smaller with just one window. Should I split my .emacs and write all configurations associated with python in a .el file (key bindings, python shell = ipython, etc ...) and for latex in another .el file (load auctex, pdf mode = default, etc ...)? How would I "call" the files and make them work appropriately (if that'a possible and good solution)?
(First, +1 to #phils's comment. You will get better help if you are more specific about what you need/want.)
Depending on just what you need/want, see also variable (not option) file-name-handler-alist. You might not need it, but you might.
You can make use of it if you intend all or particular operations on the files to involve additional actions (such as those you describe). For any operations where you do not need special treatment, just provide the default behavior. For the others, provide the default behavior plus the extra behavior (in whichever order is appropriate).
See (elisp) Magic File Names for more information.
When i do describe-function info, documentation says: Called from a program, FILE-OR-NODE may specify an Info node of the form "(FILENAME)NODENAME".
I used this syntax to open specific sections in Emacs manual like eval-expression (info "(emacs)mark").
But now i have three questions:
How to find out filename of a certain info file? (example: "elisp" for Emacs Lisp Intro)
How to find out the section name? (example: "mark" for "11 The Mark and the Region")
Is it possible to list info files and their sections before calling one with eval-expression?
Optional: is it possible to do all of the above without running info mode?
To clarify, my questions arise from the fact that the node name (example: "Shell") and title of a corresponding section (example: "36 Running Shell Commands from Emacs") differ.
How to find out filename of a certain info file? (example: "elisp" for Emacs Lisp Intro)
C-hm from the *info* buffer will tell you that the c key will Put name of current Info node in the kill ring (as well as displaying it in the echo area). From there you can yank it with C-y as usual.
The part of the node name in parenthesis is the name of the file (minus its suffix, and directory path).
To obtain the filename including its directory path (but still minus any suffix), you can call (Info-find-file "file") for the file in question ("emacs" in your example).
Note that the suffix for the file (if any) can be anything in the Info-suffix-list variable.
You can in fact pass a full file path as the argument to the info function as well. That's generally less useful, but may be handy if you managed to end up with conflicting info files. Interactively, C-uC-hi will prompt you for a full filename.
(To enter a node name interactively, you can use C-hig.)
How to find out the section name? (example: "mark" for "11 The Mark and the Region")
That's essentially the same as the first question, except it's the part of the node name after the parentheses that you want. Again, just use c to find out.
Is it possible to list info files and their sections before calling one with eval-expression?
I'm not entirely sure what you mean by this, but maybe these help?
d will jump to the main directory (as C-hi takes you to initially). This is generated from all the dir files found in the directories in the Info-directory-list variable. Each dir file contains the paths for each file, but you're unlikely to need to see those.
< or t takes you to the top node of the file, which generally presents the top-level contents for the file.
T opens an all-on-one-page table of contents for the current file.
I presents you with index entries matching a pattern, for the current file.
C-s can search through all nodes of the current file (simply type it again each time you hit the end of the current node to start searching in the next).
M-x info-apropos can be used to search all info files.
And obviously once you've arrived at a particular node via any method, you can use c to find out its name.
Also as previously mentioned, once you're in the *info* buffer, you can type g to go to any node in any info file, using the same (file) node syntax. You can omit (file) if you are already in that file, or omit node to get to the top node of the specified file. You may or may not prefer that to using
M-: (info "(file) node") RET
As a special case, g*RET renders the entire current info file in a single buffer.
Other useful Q&As on the general subject:
Reading multiple Emacs info files simultaneously
how to open *.info file in emacs in info mode?
info indexing (within and without emacs)
Also:
http://www.emacswiki.org/emacs/InfoMode
And of course:
M-: (info "(info) Top") RET
C-hih
C-hi?
Use-case:
Mark for deletion target files and directories at the dired buffer;
Execute 'dired-do-flagged-delete' (type 'x');
Result: I'm asked about confirmation for every non-empty directory being removed.
Question: is there easy way to say 'yes' one time and get all of the marked stuff (including non-empty directories) removed?
I googled that it's possible to set 'dired-recursive-deletes' to 'always' but that doesn't protect me from accidental 'delete' processing (e.g. mistyped 'x' while wrong directory is marked).
I understand that it's possible to customize emacs via lisp injections but I don't know that language so far, that's the reason why I'm asking whether there is other solution.
I think you found your answer but didn't try it.
(setq dired-recursive-deletes 'always)
And you'll only get a single prompt, asking if you want to delete the n items, and you'll get a list of them. You will not be further prompted for the directories.
I'd like to partly automate creation of GNU-style ChangeLog entries when working with source code in version control. The add-changelog-entry-other-window works with one file at a time and you have to visit the file to use it.
What I'd like to see instead is to have some command that would take an output of diff -u -p (or have integration with VC modes so it could process svn diff etc) and to create all the skeleton entries at once.
For example, if svn status shows
D file1.c
M file2.c
A file3.c
the command would create
2009-09-05 My Name <my.email>
* file1.c: Removed.
* file2.c: WRITE YOUR CHANGES HERE
* file3.c: New.
Better yet, if it could parse the changed files in some languages to an extent so it could offer:
* file2.c (new_function): New function.
(deleted_function): Removed.
(changed_function): WRITE YOUR CHANGES HERE
I have found this feature in Emacs manual, but I don't see how I could apply it here.
Any suggestions? Thanks.
EDIT: One answer suggested vc-update-change-log. Unfortunately it only supports CVS and it creates ChangeLog entries by querying the already-commited VC logs. Thus even if it supported svn and others, it would be impossible to commit the changes and the ChangeLog in the same commit.
EDIT2: Apparently add-changelog-entry-other-window (C-x 4 a) works not only from visited file but from diff hunk involving that file too. (Source) This is almost what I am looking for. This together with elisp loop to iterate through all hunks should solve it.
There is a function vc-update-change-log that automatically generates change log entries from the version control log entries.
diff-add-change-log-entries-other-window is documented to do exactly what you mentioned in EDIT2:
diff-add-change-log-entries-other-window is an interactive compiled
Lisp function in `diff-mode.el'.
(diff-add-change-log-entries-other-window)
Iterate through the current diff and create ChangeLog entries.
I.e. like `add-change-log-entry-other-window' but applied to all hunks.
Unfortunately, it doesn't work very well for, say, new files: it doesn't even include the filenames of such files in the skeletal changelog entry.
You might have better luck with gcc's mklog script, which you can get from http://gcc.gnu.org/viewcvs/gcc/trunk/contrib/mklog.
I don't know of a function that does this, but it should be easy to implement. Basically, you want to
get the changed files
for each file, call add-change-log
"Find change log file, and add an entry for today and an item for this file.
Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
name and email (stored in `add-log-full-name' and `add-log-mailing-address').
Second arg FILE-NAME is file name of the change log.
If nil, use the value of `change-log-default-name'.
Third arg OTHER-WINDOW non-nil means visit in other window.
Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
never append to an existing entry. Option `add-log-keep-changes-together'
otherwise affects whether a new entry is created.
Option `add-log-always-start-new-record' non-nil means always create a
new record, even when the last record was made on the same date and by
the same person.
The change log file can start with a copyright notice and a copying
permission notice. The first blank line indicates the end of these
notices.
Today's date is calculated according to `add-log-time-zone-rule' if
non-nil, otherwise in local time."
so the magic code is going to look something like
(apply 'make-magic-change-log-entry changed-files-list)
and make-magic-change-log-entry simply curries the add-change-log function so that the only argument is file-name — you set the other ones.
I've written a function to do something similar to what you were talking about. You can get the code at http://www.emacswiki.org/emacs/log-edit-fill