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
170 votes
10 answers
112k 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?
Fernando Briano's user avatar
97 votes
5 answers
33k 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 ...
smonff's user avatar
  • 1,575
45 votes
2 answers
10k 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, ...
Dan's user avatar
  • 32.7k
20 votes
2 answers
8k 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. ...
Keks Dose's user avatar
  • 508
20 votes
2 answers
12k 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 ...
SiXoS's user avatar
  • 303
20 votes
3 answers
8k 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 "~/....
Trevoke's user avatar
  • 2,430
17 votes
8 answers
8k 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 ...
Evan Aad's user avatar
  • 1,511
16 votes
6 answers
7k 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/ ./...
Rafa de Castro's user avatar
16 votes
1 answer
1k 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 ...
Håkon Hægland's user avatar
15 votes
4 answers
4k 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/...
nispio's user avatar
  • 8,205
15 votes
4 answers
2k 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, ...
wvxvw's user avatar
  • 11.3k
15 votes
2 answers
2k 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 (...
mbork's user avatar
  • 1,657
15 votes
3 answers
2k 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 ...
bignose's user avatar
  • 639
15 votes
1 answer
4k 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 ...
salotz's user avatar
  • 1,380
15 votes
2 answers
1k 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 ...
ebpa's user avatar
  • 7,389
14 votes
5 answers
4k 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 ...
Claudio's user avatar
  • 141
13 votes
4 answers
17k 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?
sid-kap's user avatar
  • 544
13 votes
5 answers
8k 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)?
Name's user avatar
  • 7,749
13 votes
5 answers
8k 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?
Empty_Mind's user avatar
  • 1,351
13 votes
1 answer
5k 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?
Empty_Mind's user avatar
  • 1,351
12 votes
2 answers
1k 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 ...
modulitos's user avatar
  • 2,442
11 votes
2 answers
786 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? ...
Tu Do's user avatar
  • 6,772
10 votes
4 answers
3k 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 ...
mbork's user avatar
  • 1,657
10 votes
4 answers
978 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 ...
Tim's user avatar
  • 4,987
10 votes
2 answers
1k 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-...
rneatherway's user avatar
10 votes
3 answers
736 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?
Tu Do's user avatar
  • 6,772
10 votes
1 answer
1k views

how to ignore current selection from ivy when my typed text matches one

I run into this issue from time to time when I want to create a new file but the new name matches a pattern already so my Ivy auto-complete setup will pick the matched option when I press Enter ...
Vince W.'s user avatar
  • 395
9 votes
2 answers
1k 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.
Terry's user avatar
  • 370
9 votes
2 answers
1k 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 ...
Shepmaster's user avatar
9 votes
2 answers
787 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?
Sean Allred's user avatar
  • 6,871
9 votes
2 answers
241 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 ...
cpaulik's user avatar
  • 91
8 votes
2 answers
6k 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 ...
147pm's user avatar
  • 2,937
8 votes
1 answer
1k 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$" "" ...
Nathaniel Flath's user avatar
8 votes
2 answers
2k 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 ...
Galder Zamarreño's user avatar
8 votes
2 answers
2k 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 ...
KookieMonster's user avatar
8 votes
2 answers
1k 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 ...
lap's user avatar
  • 151
7 votes
1 answer
2k views

How to prevent creating files starting with .# (lock files)?

Emacs 26 I have a file rest.api.rc. When I start editing it, the following lock file is automatically created: .#rest.api.rc After saving file rest.api.rc, the lock file .#rest.api.rc is gone. How ...
a_subscriber's user avatar
  • 3,916
7 votes
4 answers
1k 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 ...
ReneFroger's user avatar
  • 3,808
7 votes
1 answer
129 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", ...
tboyce12's user avatar
  • 322
6 votes
2 answers
1k 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 ...
Chakravarthy Raghunandan's user avatar
6 votes
1 answer
1k 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> (...
Wilfred Hughes's user avatar
6 votes
1 answer
2k views

Single function to return file contents as a string

I'm wondering if there's a terse (i.e. single function) approach for reading a file's content given its path and returning it as a string. My go-to has been: (with-temp-buffer (insert-file-...
ebpa's user avatar
  • 7,389
6 votes
1 answer
2k views

Auto-refresh files when using tramp

I am viewing remote log files using tramp mode in emacs. Is there a way to get tramp to auto-refresh these buffers when they change remotely? If this is not possible, is there a way to reload a ...
Beginner's user avatar
  • 2,671
6 votes
2 answers
303 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. ...
kain88's user avatar
  • 825
6 votes
2 answers
2k 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 ...
nasser alshammari's user avatar
6 votes
2 answers
2k views

Human readable directory tree with org-attach

By default, org-attach.el names project folders, using a UUID scheme, which is paired with headlines in org-mode, via the :PROPERTIES: drawer. I would love to find a way to make this directory ...
Adam's user avatar
  • 1,887
6 votes
1 answer
185 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 ...
zck's user avatar
  • 9,034
5 votes
3 answers
1k 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/...
h4labs's user avatar
  • 269
5 votes
2 answers
2k 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.
fhdhsni's user avatar
  • 693
5 votes
3 answers
592 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 ...
Madhavan's user avatar
  • 1,977

1
2 3 4 5 6