M-x revert-buffer will do exactly what you want. It will still ask for confirmation.
Another option (my favorite) is the below function:
;; Source: http://www.emacswiki.org/emacs-en/download/misc-cmds.el
(defun revert-buffer-no-confirm ()
"Revert buffer without confirmation."
(revert-buffer :ignore-auto :noconfirm))
Use C-x C-f and type out /su::/etc/hostname or /sudo::/etc/hostname as applicable.
This uses the TRAMP package, which is distributed with Emacs. This package provides access to remote files, and more generally to files that Emacs can't open directly.
There is also auto-revert-mode which does it automatically and gives you feedback.
From the doc string:
auto-revert-mode is an interactive autoloaded compiled Lisp function
(auto-revert-mode &optional ARG)
Toggle reverting buffer when the file changes (Auto Revert mode).
With a prefix argument ARG, enable Auto Revert mode if ARG ...
Another option, which I use, is find-alternate-file bound to C-x C-v. This opens a file reusing your current buffer.
By default, it points to the file you're currently on, so you can just type C-x C-v RET to reload your file. It won't prompt unless your buffer has unsaved data.
Some non-text modes like image-mode (used for rendering pictures, pdfs, svgs......
Emacs predates contemporary window-based operating systems, so its
terminology also predates the current terms. Unfortunately, it means that new users and experienced users sometimes have trouble making themselves understood to each other, since they're using the terms in different ways.
"Frames" are to Emacs what "windows" are to everything ...
There's no need to do all that.
Still in the original file, hit C-x C-w. You will be prompted for a new filename.
Hit M-n, and the current filename will be inserted for you.
Edit what you want and hit RET to save the file to this new name.
You will still have the original file. If you want to go back to it, just visit it again with C-x C-f.
I think what you're looking for is C-M-j (ivy-immediate-done) in the mini buffer. This function is described as follows in the Ivy manual:
Exits with the current input instead of the current candidate (like
This is useful e.g. when you call find-file to create a new file, but
the desired name matches an existing file. In that ...
C-h f dired tells you the answer. Just pass to dired, as the DIRNAME argument, a list that has as its car the Dired buffer name you want (any string) and as cdr the list of file names you want listed in the buffer. Generally, you want to use absolute file names. For example:
(dired (list "My Dired Buffer Name*" ; The Dired buffer name
@Sigma's answer is a good start, but it doesn't filter by executability, nor does it allow for extra suffixes. On windows, for example, running a can invoke a.exe, if that's what's in your path.
So use executable-find; here's the definition (taken from Emacs' sources), if you're curious:
(defun executable-find (command)
"Search for COMMAND in `exec-path'...
In Emacs terminology, these are two different steps:
Associate files with the .ts extension with the major mode typescript-mode.
Run the function tss-setup-current-buffer when Typescript mode starts.
To choose which major mode to use for certain file names, add an entry to the variable auto-mode-alist. Put the following line in your init file:
(I think this was added in Emacs 25)
here's the link to the manual: https://www.gnu.org/software/emacs/manual/html_node/elisp/Contents-of-Directories.html
Return all files under directory whose names match regexp. This function searches the specified directory and its sub-directories, recursively, for files whose basenames (i....
What existing command gets the current file buffer's file name like this?
Unfortunately there is no ready made command for this, but we can make one as follows:
(defun name-of-the-file ()
"Gets the name of the file the current buffer is based on."
(insert (buffer-file-name (window-buffer (minibuffer-selected-window)))))
The magic is ...
While an ido command is active (ido-find-file in this case), you can drop back to the non-ido version of the same command (find-file in this case) using the ido-default binding C-x C-f for ido-fallback-command.
To answer you question,
The first C-x C-f will call ido-find-file.
The second C-x C-f will fall back to find-file.
Then you can do C-a C-y C-k RET ...
I'm using Spacemacs (on Windows 10 if that matters) with the default keybindings. This may differ from your configuration, but I found the following ways to open files via Helm-Find-Files:
Open Helm-Find-Files - SPCff
Type in filename (via tab completion etc.). Once file has been selected, there are 3 options I use for opening the file:
Option 1. Tab to ...
I suggest you use the vlf package.
It handles opening larges files in chunks and is very performant, I use it regularly to open files ~2gb.
In your config, require vlf-setup to have vlf ask you if you want to use vlf every time you try to open a large file. This means it works with anything that uses find-file such as helm-find-files.
You don't need to do that, if that's your question.
C-x C-f /some/new/directory/newfile.txt
Emacs prints a message to let you know that the directory /some/new/directory/ does not yet exist: Use M-x make-directory RET RET to create the directory and its parents.
Insert text into the new buffer for new file newfile.txt.
C-x C-s to save the file.
C-u C-x d
This let's you enter arguments for how Dired should list files. By default it says -al at the prompt. Add R to that, ending up with -alR. Type RET.
Select/type a directory and then press RET.
This will recursively open all directories from the one you select, and below.
From here, type % m to mark all files matching a certain file ...
Using browse-url-of-file should work when given a directory.
You could implement a command that opens the directory of the current file like this:
(defun browse-file-directory ()
"Open the current file's directory however the OS would."
(browse-url-of-file (expand-file-name default-directory))
(error "No `...
I keep the Emacs manual and Elisp manual on speed dial for questions like these.
From the Elisp manual on indirect buffers:
Function: buffer-base-buffer &optional buffer
This function returns the base buffer of buffer, which defaults to the current buffer. If buffer is not indirect, the value is nil. Otherwise, the value is another buffer, which is ...
I'd argue that your usage is idiomatic elisp, since the buffer's name is a perfectly appropriate boolean value in its own right. Quoting from the manual:
There is an important aspect to the truth test in an if expression. So far, we have spoken of `true' and `false' as values of predicates as if they were new kinds of Emacs Lisp objects. In fact, `false' ...
Emacs calls this reverting.
You can revert the current file with M-x revert-buffer. This prompts for confirmation whether the file has been modified or not, except for files that match patterns listed in the variable revert-without-query (see the manual for details). Another occasional annoyance of revert-buffer is that it resets the file mode to the ...
Emacs comes with auth-source.el. I would not try to roll my own version of it.
auth-source makes it easy to read from ~/.authinfo.gpg. Good programs will already support authinfo. A quick search suggests that ERC can use authinfo.
For your random off the shelf MELPA programs you can easily use authinfo to retrieve your password from ~/.authinfo.gpg like ...
How I can prevent generating the lock file .#rest.api.rc?
Set the user option create-lockfiles to nil, but note that this can stop Emacs from being able to detect simultaneous edits to the same file.
C-hvcreate-lockfilesRET says the following:
create-lockfiles is a variable defined in `src/filelock.c'.
Its value is t
This variable is safe as a file ...
The auto-mode-alist variable does what you need. Never bind anything to the major-mode variable.
The documentation explains how you can set major-modes per file extension and, most importantly, it explains how to treat multiple extensions.
Alist of filename patterns vs corresponding major mode functions. Each element looks like (REGEXP . FUNCTION) or (...
There doesn't seem to be a command to get this info interactively, although you can use dired as @jrm suggests.
You can get this information with the following elisp code:
This will return a list like this:
(nil 1 "lh" "users"
(20614 64019 50040 152000)
(20000 23 0 0)
(20614 64555 902289 872000)
Use find-file with tramp. At the prompt /sudo::/etc/ssh/ssh_config will use sudo and a subshell to open that file with root privileges. When sudo is first used it will prompt for a password, but until that session closes you can edit any file with those permissions by prefixing with the existing /sudo:: command.
See http://www.gnu.org/software/tramp/ for ...