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?
Related
A directory titled auto-save-list appeared in my .emacs.d folder. In my init.el file, I did not explicitly mention I want this folder to be made. What is the purpose of this folder? I noticed it seems to always be empty: files being auto-saved (starting with #) appear wherever the original file being edited is, not in the auto-save-list directory.
If you search the manual or its index for auto-save-list you will find:
Emacs records information about interrupted sessions in files named
‘.saves-PID-HOSTNAME’ in the directory ‘~/.emacs.d/auto-save-list/’.
This directory is determined by the variable
‘auto-save-list-file-prefix’. If you set ‘auto-save-list-file-prefix’
to ‘nil’, sessions are not recorded for recovery.
– C-hig (emacs)Recover RET
I did not explicitly mention I want this folder to be made.
Emacs and elisp libraries in general write to ~/.emacs.d/ when they need to save data. That's one of the purposes of this directory -- to provide a common place for such files to be written to; and this typically happens without asking explicit permission (although it's also pretty common for you to be able to customize the filename in question if you so wish).
phils already answered the specific question, but to answer the more general question of what to do about miscellaneous files automatically created by Emacs, check out the no-littering package.
Auto save files (the ones with '#') are not handled by no-littering, but the readme gives a work around for those if you wish.
I have a folder /var/~/. In config .emacs I wanna load some files from this folder.
I try to use (load-file "/var/~/foobar.el"), but emacs alerts File error: Cannot open load file, ~/foobar.el.
Furthermore I couldn't even open the files under this folder with c-x c-f. In minibuffer the path will auto be redirected to my home.
How could I load files in that folder?
You need to rename your directory.
load-file is a simple wrapper around load, which passes the given file name through substitute-in-file-name. From the docstring of substitute-in-file-name (emphasis mine):
Substitute environment variables referred to in FILENAME. `$FOO' where FOO is an environment variable name means to substitute
the value of that variable. The variable name should be terminated
with a character not a letter, digit or underscore; otherwise, enclose
the entire variable name in braces.
If `/~' appears, all of FILENAME through that `/' is discarded. If `//' appears, everything up to and including the first of those `/' is discarded.
In other words, substitute-in-file-name throws away everything before /~, turning /var/~/foo.el into ~/foo.el.
I completely fail to see any reason in this behaviour, but it is what it is, and you cannot (easily) work around it, so renaming is your best way out of this dilemma.
It's a reasonable thing to do, anyway. Using ~ as directory name is bad idea on Unix systems generally, not just for Emacs alone.
lunaryorn explained your problem well, and I agree with his suggestion that not using ~ in file paths is the best solution. However, If you can't rename these paths for whatever reason, I believe you can work around substitute-in-file-name by loading a relative file path as documented here.
Basically, you need to add nil to your load-path variable, then set your default-directory variable to the troublesome path, finally then load the file using a relative name. e.g.:
; adding nil causes load to also search your 'default-directory'
(setq load-path (append '(nil) load-path))
(setq default-directory "/tmp/~/")
(load "foobar.el")
Note that if you suspect the file name might exist (be loaded from) elsewhere in your load-path you would need to ensure the file you want is first in the load-path.
See How programs do loading.
I'm working on a golang project, where there are a lot of files with the same name, in different directories.
For example, there's a parser class, and a handler class, both of which have separate directories, but the filenames in the two directories are nearly identical.
Is there a way to tell emacs to show path as buffer name prefix, instead of affixing <2> to the repeating buffer names as a suffix?
See the Emacs manual, node Uniquify, and user option uniquify-buffer-name-style.
C-h r g uniquify RET
You can customize the option value to forward to get the behavior you request.
In Emacs versions older than Emacs 23 you will not find node Uniquify in the manual, and you will need to explicitly require library uniquify.el in your init file (~/.emacs):
(require 'uniquify)
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))
How can I check the identity of someone who has created a buffer in Emacs and then later on check whether is the same user accessing that buffer? I mean something like "Who Am I?" in Unix command.. and then check if the same user is accessing that document? --> I want a function or a way to this in my own code
Note the difference between a buffer and a file: A file is something that sits on your hard disk, such as a .jpg image file or a .mp3 aufio file or a .txt file. Some of those files - typically text files - you might want to edit with Emacs. To do so, you can load the file into Emacs - this is called "visiting" a file in Emacs lingo. The contents of the file are displayed in a buffer. But note that you could also have a buffer that is not associated with a file at all - for instance the *scratch* buffer that gets displayed if you start up Emacs without specifying a file.
Thus files and buffers are pretty much orthogonal concepts, although often times you create buffers by visiting a file, and you save the contents of a buffer by writing to a file. (You can create a buffer that is not associated with a file by typing C-x b buffer-name where buffer-name is an identifier not used by any of the already existing buffers.)
A buffer exists only inside a running Emacs. This is why the comments and answers you have gotten so far may not have been what you're looking for: the notion of the creator/owner of the buffer is confusing, because it is obviously the person who's sitting at the keyboard at that particular moment.
Speaking of the owner/creator of a file makes much more sense. In a multi-account setup, more than one user can write to the same disk, and so they might have access to the same files. Now it can be interesting to know who has access, and in particular who owns the file or when it was last modified. In Elisp, you can use the function
(file-attributes FILENAME &optional ID-FORMAT)
to get a list of attributes associated with the file. If your current buffer is visiting a file at all, you can combine that function with the function
(buffer-file-name &optional BUFFER)
which returns the file the buffer is visiting. For a buffer that is not visiting a file, this function returns nil.
Note, however, that some information you might be interested in is not available through (file-attributes ...), such as who last accessed the file and/or who last modified it. This is not so much Emacs' fault, but comes from the fact that the operating system does not store such information.
Also note that the current owner of a file might not necessarily be the person who created it as someone with the required privileges can chown a file after its creation.
To receive information about the current user in the sense of whoami, you can check out the variables
user-login-name
user-real-login-name
user-full-name
by typing C-h v variable-name.
AFAIK seen from system, Emacs is a single process, owned by the user who started it
(getenv "USER")
is the respective to
echo $USER