Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
6 votes
Accepted

How to make a temporary directory that gets deleted once the body is finished?

make-temp-file can be used to make a directory instead of a file, this example simply calls make-temp-file, then removes the directory afterwards. (let ((temp-dir (make-temp-file "foo" t))) (unwind-...
xo6xu's user avatar
  • 76
5 votes

How to import directory structure to org-mode heading?

Try C-u M-! and inserting the output from commands below that I adopted from another question / Answer find . |sort|sed -E -e 's;(^.*[^/]/);\1 ;;s;([^/]*/);*;g;s/^\.$//' That will give you a ...
alls0rts's user avatar
  • 366
4 votes
Accepted

Set default-directory relative to the place an Elisp function is defined

You can define a variable in the script that records the directory: (defvar my-shell-directory (if load-file-name (file-name-directory load-file-name) default-directory)) You can then ...
Lindydancer's user avatar
  • 6,170
4 votes
Accepted

Create a directory when a file has a similar name

You can try using C-M-j, as explained here Q: How do I enter an input that matches one of the candidates instead of this candidate? Example: create a file bar when a file barricade exists in ...
Manuel Uberti's user avatar
4 votes
Accepted

How can backup-directory-alist be set to save in the files directory?

Just use relative directory name (setq backup-directory-alist '(("." . "editorbackups"))) Function make-backup-file-name-1 will make directory name relative to file's directory and create it: ;; If ...
muffinmad's user avatar
  • 2,310
4 votes
Accepted

How to open a folder as project in emacs?

Emacs packages will automatically find the project root, company-gtags (for code completion) from https://github.com/company-mode/company-mode counsel-git-grep (for grepping) and counsel-git (for ...
chen bin's user avatar
  • 4,877
3 votes

How to make a temporary directory that gets deleted once the body is finished?

;; Inspired from `dired-create-directory` code. (defun with-temp-dir (dir) "..." (let* ((expanded (directory-file-name (expand-file-name dir))) (try expanded) new) (...
Drew's user avatar
  • 77.8k
3 votes

How to get Emacs to automatically open a specific directory on startup?

Oops, never mind, I read the link I provided earlier again and I finally got how to turn it into an ~/.emacs modification. Specifically I added: (setq initial-buffer-choice "~/Documents/CodeLite/CPP-...
Josh Pinto's user avatar
2 votes

Create a directory when a file has a similar name

Yes, there is. If you append a forward slash (/) after your directory name, ivy-mode will be forced to treat it as a directory path.
Wojciech Gac's user avatar
2 votes
Accepted

How to import directory structure to org-mode heading?

You can use org-fstree (install from MELPA or from here). It seems to do exactly what you want, it even makes each heading be a link to the corresponding file or folder. To use it, just put a line ...
deprecated's user avatar
  • 2,835
2 votes
Accepted

Open Dired for an arbitrary set of files

Not exactly sure what you're asking, but perhaps this will help. Offhand, a guess is that bookmarking Dired buffers is close to what you are looking for. Dired itself lets you have a Dired buffer ...
Drew's user avatar
  • 77.8k
2 votes

Open Dired for an arbitrary set of files

fA.cpp fB.cpp fC.cpp No-frills approach in Dired: %m f[A-Z]\.cpp RET to mark files t to invert the marks k to hide the marked files
phils's user avatar
  • 51.5k
2 votes

Open emacs in Dired mode

If you provide a directory on the command-line, it opens in dired mode. For example emacs . ...will open the current directory in dired mode. The variable `dired-listing-switches' contains the ...
Realraptor's user avatar
  • 1,293
2 votes

Set a global default directory

The code below uses a new feature in 26.1 called variable-watcher. It allows a function to observe changes in some variable's value. But more or less the same could be achieved by using hooks and/or ...
politza's user avatar
  • 3,346
2 votes

Relative directory Logic

There is command cd: M-x cd (or bind it to a key). There is also Dired: C-x d, then C-h m. Or C-h r g dired, which takes you to node Dired of the Emacs manual. Both of those should help you. See ...
Drew's user avatar
  • 77.8k
2 votes

How to get all full path list by a folder name?

(cl-remove-if-not #'file-directory-p (directory-files-recursively "name-of-directory" "autoload" t)) directory-files-recursively seems not well-known for some reason. See Directories for a fuller ...
rpluim's user avatar
  • 5,315
1 vote
Accepted

How can I get projectile-grep et al to choose the project before searching?

s-p p (where s-p represents whatever prefix key you have chosen) will allow you to choose a different project. It then prompts you to open a file from that project; you can just open whatever file is ...
db48x's user avatar
  • 18.2k
1 vote

How to obtain file path from LISP file loaded by command line?

Emacs manual node Action Arguments tells you this about command-line option --load: Load a Lisp library named FILE with the function load. If FILE is not an absolute file name, Emacs first looks ...
Drew's user avatar
  • 77.8k
1 vote

File-missing "No such file or directory" "c:/emacs-26.1-x86_64/bin/%HOMEDRIVE%%HOMEPATH%/"

You might consider setting the HOME environment variable to "P:". I also have HOMEDRIVE set and HOMEPATH set (to "U:" and "" respectively), however Emacs wants to use ...
Remi's user avatar
  • 11
1 vote

How to find a directory with given depth from current directory?

You can use the ls command of the built-in eshell for listing the files with some predefined depth. You have to specify the depth by the right number of concatenated file name generator expressions */...
Tobias's user avatar
  • 33.2k
1 vote

How to find a directory with given depth from current directory?

Library find-dired+.el can help with this. C-h f find-dired: find-dired is an interactive compiled Lisp function in find-dired+.el. (find-dired DIR ARGS &optional DEPTH-LIMITS EXCLUDED-...
Drew's user avatar
  • 77.8k
1 vote

How to find a directory with given depth from current directory?

The elgrep-search command has options :mindepth and :maxdepth. Elgrep is available via package-install from the melpa package archive (instructions how to add melpa to package-archives can be found on ...
Tobias's user avatar
  • 33.2k
1 vote

How to find a directory with given depth from current directory?

I'd be inclined to use find for that: (let ((dirname (expand-file-name "~/")) (depth 3)) (split-string (shell-command-to-string (format "find %s -mindepth %d -maxdepth %d -type d -...
phils's user avatar
  • 51.5k
1 vote

Set a global default directory

I am using this setting in my ~/.emacs.d/init.el file to set $FOO as my default directory: (add-hook 'find-file-hook (lambda() (setq default-directory (substitute-in-file-name "$FOO/"))))
klopps's user avatar
  • 11
1 vote

Split window with new buffer and spawn a new shell in same (possibly remote) directory as old buffer

I use shell pop to do what I think you are asking for. When I press Ctrl-t, it splits the window, creating a new buffer with a shell in that buffer set to the directory that matches the directory of ...
Gina White's user avatar
1 vote

Tutorial Exercise - C-x C-s Save -- Write Protected issue in OSX

It looks like you are trying to save the file ~TUTORIAL at the root of the system (/) instead of saving the file TUTORIAL in your home directory (~/). Typically when you open a new file Emacs will ...
jerome's user avatar
  • 213
1 vote

Open Dired for an arbitrary set of files

Install https://github.com/technomancy/find-file-in-project (available at http://melpa.org) M-x find-file-in-current-directory or find-file-in-project-by-selected or find-file-in-project you got ...
chen bin's user avatar
  • 4,877
1 vote
Accepted

Tramp and non-existent directories

Tramp must check whether the directory, you intend to create the new file in, does exist. This can be done only by checking on the remote host. Asking for the password is part of the connection to the ...
Michael Albinus's user avatar
1 vote
Accepted

How to Filter Directory Contents?

directory-files accepts match-regexp argument: (directory-files "my/path/to/dir" nil "^[0-9][0-9.]*$") should return ("4.03.0" "4.02.9") and you extract the first element of the list using functions ...
sds's user avatar
  • 6,124
1 vote

How to get Emacs to automatically open a specific directory on startup?

To open a directory at startup you can also insert (find-file "/path/to/dir") in init.el
Matthias's user avatar
  • 785

Only top scored, non community-wiki answers of a minimum length are eligible