Questions tagged [files]

Use this tag for questions about moving, deleting, or opening files. Or for questions about the difference between a buffer and its file. For topics such as "Saving Files", use "buffers" instead.

Filter by
Sorted by
Tagged with
113
votes
9answers
70k views

How do I reload a file in a buffer?

I usually work on files which are updated in the file system via version control. What's a quick way to reload a file without having to C-x C-f the file again and getting asked if I want to reload it?
56
votes
5answers
12k views

Edit file with super-user rights

When you have to edit system files, it's an usual situation that you launched Emacs with a normal user before, so the file will be write-protected. What can I do to gain root privileges? I mean ...
29
votes
2answers
5k views

What's the difference between a buffer, a file, a window, and a frame?

When posing questions on this site, people sometimes talk about "windows" when they mean "frames," and "buffers" or "files" when they mean "windows." So: Q: What is the difference between a buffer, ...
17
votes
2answers
5k views

Save current file with a slightly different name

My files have long filenames and a part of the filename is a date and a version number. Often I'd like to save the file in the buffer using nearly the same name, just change version number or date. ...
16
votes
3answers
3k views

How can I find the path to an executable with Emacs Lisp?

My current use case is to find where the Cask executable is (it can be installed in at least two places, and there's an issue open about this). I need to require cask this way: (require 'cask "~/....
15
votes
6answers
3k views

Recursively list all files and sub-directories

Is there a way, possibly using a package, to recursively list all the files (with paths) and sub-directories (or at least the empty sub-directories, since the paths to the non-empty ones can be ...
14
votes
4answers
1k views

How to tell Ido to get out of the way when I can already just paste the file name?

I'm trying to make myself use Ido mode. Some times it's nice, but other times it is extremely stupid. Here's my greatest disappointment. I read some log with full file names, then I copy one name, ...
14
votes
2answers
7k views

Run command when opening a file of a specific filetype

I'm trying to get a lisp script to run some commands for me when I open a file of a specific filetype. I know that I'm working in the correct init file because if I remove the theme from it, emacs has ...
12
votes
3answers
976 views

Put the current file name in the minibuffer

How can I insert the file name of the active file buffer into a command? When I invoke a command that needs a file name, I am often doing so from a file buffer and want the name of that file while ...
12
votes
1answer
3k views

Open file in new window after searching it with helm

As written in A Package in a league of its own: Helm there's a way to search for a file using Helm decide after searching whether open it in same or other window My question is: How?
12
votes
1answer
832 views

How to prevent Emacs from breaking hard links?

Let's say I have two files file1 and file2: $ echo aaa >file1 $ ln file1 file2 Then I check that the inodes are the same: $ ls -i 18749779 file1 18749779 file2 which shows that the two files ...
12
votes
1answer
481 views

Display recursive folder sizes in-line in dired?

I'd like to display the recursive size (the value that would be reported by du) of folder contents in-line in the dired buffer as an additional column or in place of the directory file size. Is this ...
11
votes
2answers
826 views

What's wrong with `find-file-noselect`?

In a recent answer by lunaryorn, he stated: However, I'd recommend against most other parts of Org, for reasons already stated in comments: It's old, and full of legacy and harmful practices (...
11
votes
2answers
975 views

Elisp: How to exclude sensitive information from an init file? (ie login credentials)

I want to define a log in function in my init script, but I don't want to hardcode my login credentials. I think a good workaround is to have my init script read in my login credentials from a local ...
11
votes
1answer
2k views

Open large files?

I want to open just the head of a large file. I know you can use a shell command (M-! RET head file RET), but I lose helm completion, it opens in a separate window, and the buffer has the ...
11
votes
5answers
5k views

Comparing two text files on a Windows system

Since ediff-files and ediff-buffers result in apply: Searching for program: no such file or directory, diff error on windows machines. How to compare two files using Emacs on a windows system?
10
votes
2answers
497 views

Programmatically insert files into Dired buffer

I have a list of file names (with full path) and I want to create a Dired buffer listing this set of files. How would I go about doing that? How do I create a Dired buffer from a list of file names? ...
10
votes
4answers
5k views

What is the easiest way to open the folder containing the current file by the default explorer of the OS?

What is the easiest way to open the folder containing the current file by the default explorer of the OS (e.g. explorer.exe in the case of Windows OS)?
10
votes
3answers
426 views

Get all filenames in current Dired buffer with Elisp

As the title suggests, how do I get all the file entries in a Dired buffer using Elisp?
9
votes
4answers
3k views

Recursively open files matching regexp in marked directories

Generally speaking, I would like to be able to open all files within a given set of directories (and their subdirectories) where the filename matches a given regexp. For example /home/nispio/...
9
votes
4answers
2k views

How to check whether a buffer is visiting a file?

I'd like to check whether some (say, current) buffer is visiting a file or not. I could say: (if (buffer-file-name) ...) but it seems to be not very elegant - what I'm interested in is only the ...
9
votes
4answers
489 views

Opening a new file whose parent directory doesn't exist yet

When opening a new file whose parent directory doesn't exist yet, I either open a shell window, or an Emacs shell buffer, and then mkdir the directory in it. I find this cumbersome. Is there an ...
9
votes
2answers
621 views

How can I create a dired buffer listing all open files?

I have a mechanism for burning items to disc from a dired buffer. Unfortunately, the file's I've patched are strewn accross the file system. How can I create a dired buffer from all open files?
9
votes
2answers
169 views

How to write a major mode that does not open the file but provides a view on it

I would like to write a major mode for inspecting netCDF files. These are binary files which can be multiple GB in size. So I don't want to open them in emacs. The interaction that I have in mind is ...
8
votes
2answers
777 views

Can I view within Emacs the properties of a file which I already opened?

I've opened a file in Emacs. I'd like to view information about that file such as creation date, size, etc. within Emacs. Is there a key shortcut or any Emacs command for that? Thanks.
8
votes
4answers
3k views

Ivy disable completion for a command in minibuffer

Can I disable ivy completion for a single command while in minibuffer? For example I am in folder ~/code/study/ . If I open find file and autocomplete with Ivy I will see Find file: ~/code/study/ ./...
8
votes
2answers
365 views

How should I get the filename of the original buffer in an indirect cloned buffer?

I wanted to look at different portions of a buffer in two different frames, as I have two monitors of different shapes that I can't easily span a single frame over. Some googling led me to use clone-...
8
votes
4answers
2k views

How do I search and replace over a set of files?

I'd like to define a set of files within which I can search and replace text. To clarify: I would like to be able to search, e.g., in all files xk*.tex in a given directory (and excluding backup ...
7
votes
4answers
10k views

Spacemacs: kill buffer and kill window in one command?

Is there a spacemacs command that both closes the window and kills the buffer? In other words, the equivalent of Vim's :q?
7
votes
2answers
1k views

Saving open file list and buffer command history in between sessions

I've discovered desktop-save-mode which allows Emacs to be closed and when it reopens, it appears with the same files that were open before. I want to take this a bit further and I was wondering if I ...
6
votes
2answers
842 views

How can I jump to a file and line number from a list in a buffer?

I have a buffer with content like: src/file4.rs:9 src/file4.rs:33 src/file4.rs:64 I'd like to be able to put my cursor on a line and jump to the appropriate file / line in the other window, just ...
6
votes
1answer
597 views

Specify major-mode for files with multiple extensions

In my .emacs file, I have: (setq-default major-mode (lambda () (let ((buffer-file-name (replace-regexp-in-string "\\.tmp$" "" ...
6
votes
1answer
179 views

Why does calling expand-file-name indirectly produce a different result?

Running the following in ielm in emacs -Q: ELISP> (defun wh/expand-file-name (name &optional default-directory) (expand-file-name name default-directory)) wh/expand-file-name ELISP> (...
6
votes
2answers
1k views

.tramp_history files

I have noticed that opening a tramp connection on remote hosts sometimes created a .tramp_history file in the user's directory. Is there any way to disable such a behavior? I have to log in to many ...
6
votes
2answers
196 views

Save all open files in current folder and subfolders

Some of my projects are organised in way that the there isn't one make file at the top route of the project (git/svn/...) folder but I have several small Makefiles in subfolders of the project. ...
6
votes
1answer
771 views

How to split a long org file into separate org files?

I've an huge org file HUGE.org with this structure: * ID-HEAD-1 Title1 :TAG: bla bla bla * ID-HEAD-2 Title2 :TAG: bla bla bla ... * ID-HEAD-N TitleN :TAG: bla bla bla and I want to split HUGE.org ...
6
votes
1answer
84 views

Emacs handle when file renamed externally

How can I configure Emacs to update a buffer's file association when the file is renamed externally? In Textmate, I can open a file "foo.txt", use a different program to rename the file to "bar.txt", ...
5
votes
3answers
715 views

Load all org files into buffers?

I've got a couple dozen org files that I'd like to have loaded at once. They're in a directory structure something like this: org/dev org/dev/python.org org/dev/emacs.org ... org/dev/ios org/dev/ios/...
5
votes
4answers
520 views

Does some command exist, which goes to the next file of the current directory?

I'm looking for a command inside Emacs. For example, you are currently in a directory. In the directory there are 2 files: foo.txt and bar.txt. I have foo.txt opened in Emacs and is being ...
5
votes
1answer
994 views

Character encoding when copying some text from somewhere to Emacs and saving to a file

Suppose I copy some text from a source (e.g. a webpage, a text file opened in an editor such as gedit or emacs) to a buffer in emacs, and then save the buffer to a text file. When I copy the text ...
5
votes
1answer
546 views

Get filename from dired using elisp

Using elisp, I call this function (dired "~"), for example, to get to my Home directory in dired mode. When I press RET on one of the files, I want to capture the file path and store it in a variable ...
5
votes
1answer
104 views

How do I include non-code resources as part of an Emacs package?

I have a project that wants to play a sound file. I'd like to distribute this project in MELPA. There are two issues I'm having with that. They're both part of the question "how do I use resources in ...
5
votes
1answer
704 views

How to set temporary file directory for flycheck eslint (outside of current directory)

flycheck-mode creates temporary files in the current directory. That is annoying. How can I disable/set the default place for these temporary files. I use javascript eslint syntax checker for react ...
5
votes
0answers
93 views

Why is cloning of file buffers prohibited?

Why does clone-buffer not work on file buffers. I can make it work by the following advice: (advice-add 'clone-buffer :around (lambda (oldfun &rest args) "Allow cloning file buffers." ...
5
votes
0answers
376 views

Drag-and-drop file does not work anymore

Using Emacs 24.5 on a Gentoo/Kde workstation. Drag-and-drop of files used to work okay (as far as I remember), to open a new buffer on the dragged file. Same behaviour when using emacs -Q. It does ...
4
votes
2answers
2k views

How to do a simple write to file

I simply need to take the output of org-element-parse-buffer and put it in a file -- maybe with some "if-does-not-exist" etc. bells and whistles. In CL I have with-open-file and write as tools. For ...
4
votes
2answers
1k views

What's the equivalent of `helm-find` in ivy/counsel? I want to find files **recursively**

helm-find is Preconfigured ‘helm’ for the find shell command I need the same functionality with ivy/counsel.
4
votes
3answers
333 views

Switch buffer to the file path in current cursor position

My .emacs file contains multiple file names as, (load "~/.emacs.d/others/keymaps.el") (load "~/.emacs.d/others/py.el") (load "~/.emacs.d/others/web.el") Is there a way any library, gives way for me ...
4
votes
2answers
651 views

How to make emacs automatically kill buffer after invoking delete-file command?

Whenever I delete a file that I no longer need in emacs using delete-file command, the buffer associated with the file is still open in emacs. Is there a way I can change this behaviour so that ...
4
votes
2answers
442 views

Backup saved buffers to Dropbox (or other specific directory)

Is it possible to customize Emacs so that whenever I save a file, Emacs also copies it to a specific folder? This directory could be, for instance, D:\my_backups or C:\Users\username\Dropbox\...