9 votes
Accepted

How do I unexpand a file name?

Use function abbreviate-file-name. C-h f says: abbreviate-file-name is a compiled Lisp function in `files.el'. (abbreviate-file-name FILENAME) Return a version of FILENAME shortened using `...
user avatar
  • 69.7k
6 votes
Accepted

File mode name with -mode suffix or not?

Don't name your file x-mode.el if it does not actually provide a mode of some sort: that seems confusing. If you are providing library x, just call the file x.el. From what I've seen, most modes (...
user avatar
  • 19.2k
6 votes
Accepted

How to map or iterate over a list of files and set the result to `org-agenda-files`?

Without looking up any of the Org variables or functions you refer to, here's a guess at what you're trying to do. They both do the same thing: iterate over a list of file names, expanding them in ...
user avatar
  • 69.7k
6 votes
Accepted

Automatically Uniquify Certain Buffers

The soon awaited Emacs 28.1 will be shipped with this change: ** User option 'uniquify-buffer-name-style' can now be a function. This user option can be one of the predefined styles or a function to ...
user avatar
  • 399
5 votes
Accepted

Abbreviate "/home/user/file" to "~/file" in formatted fields (frame-title-format, etc.)

Use function abbreviate-file-name. C-h f tells us: abbreviate-file-name is a compiled Lisp function in files.el. (abbreviate-file-name FILENAME) Return a version of FILENAME shortened using directory-...
user avatar
  • 69.7k
4 votes
Accepted

How to get absolute file names, to use with `cd`?

Use quotes to make cd think /Nuskha/With Space/file is one single argument, not two, e.g., $ cd "/Nuskha/With Space/file" $ cd '/Nuskha/With Space/file' You can also use shell-quote-argument: (...
user avatar
  • 13.6k
4 votes
Accepted

How to test if absolute path is a root file/directory

Not sure what you're asking, but perhaps this is it (from Dired+): (defun diredp-root-directory-p (file) "Return non-nil if FILE is a root directory." (if (fboundp 'ange-ftp-root-dir-p) (...
user avatar
  • 69.7k
4 votes
Accepted

file-truename and tramp

The behavior as described by you is the intended one. If you want only the remote pathname, you must call (file-remote-p (file-truename "./file.ext") 'localname)
user avatar
4 votes
Accepted

Why does thing-at-point not consider plus as a filename character?

Not sure why it's not in the default set of chars but you can add it yourself. The relevant variable is thing-at-point-file-name-chars. For example: (eval-after-load "thingatpt" (setq thing-at-...
user avatar
  • 19.2k
4 votes

string splitting (renaming files)

In dired, type C-xC-q to switch to editable dired mode. Start query-replace-regexp with C-M-% Enter \([^ ]+\)_\([0-9]+\).png as the search pattern, and \2_\1_.png as the replacement. Type y to ...
user avatar
  • 43.5k
4 votes

How to match the nondirectory part of a filename with a regular expression?

I'd do (equal "COMMIT_EDITMSG" (file-name-nondirectory <file>))
user avatar
  • 25.3k
3 votes

Macro definition

For one thing (and I am not at all sure there isn't another problem), the call to expand-file-name in the macro body is scrambled. It should be (expand-file-name (concat ,module ".el") j/...
user avatar
3 votes
Accepted

Rename org buffers to org's +TITLE instead of filename

The following code renames the buffer to the value of #+TITLE: when you open the Org file. This is the most simple version. It does not update the buffer name when you add or change the title. But in ...
user avatar
  • 30.3k
3 votes
Accepted

How to duplicate a file in Dired?

This should do more or less what you request. (defun dired-duplicate-this-file () "Duplicate file on this line." (interactive) (let* ((this (dired-get-filename t)) (ctr 1) ...
user avatar
  • 69.7k
3 votes

Increment file name and create a new version of the file

The following elisp code should define a function write-file-increment doing what you want, except for the "preserving length" part. If the file name does not contain a number, it adds "-1". Apart ...
user avatar
  • 4,113
3 votes

Why does emacs recognize my wildcard with finding file but not with searching buffer?

Use of * in a file or directory name is a wildcard for glob matching. (It is unrelated to regular-expression matching, by the way). Buffer names are not necessarily file names. There are many ...
user avatar
  • 69.7k
2 votes

Why does thing-at-point not consider plus as a filename character?

because in thingatpt.el the var thing-at-point-file-name-chars is defined: (defvar thing-at-point-file-name-chars "-~/[:alnum:]_.${}#%,:" "Characters allowable in filenames.") If you set it, that ...
user avatar
  • 4,231
2 votes
Accepted

Org links file name encoding issue

Have you tried using org-link-unescape to get back the original filename? Something like: :face '(lambda (path) (if (file-exists-p (org-link-unescape path)) '(:foreground "green"...
user avatar
  • 4,099
2 votes
Accepted

Macro definition

M-x pp-macroexpand-last-sexp is your friend. It shows you the code that your macro is expanding into, which is: (with-eval-after-load (expand-file-name (concat "latex" ".el&...
user avatar
  • 43.5k
2 votes
Accepted

Converting init file on Mac/Linux to Windows

No. Emacs on MS Windows uses the GNU/Unix conventions of ~ and / as directory separator, just fine. See also the Emacs manual, nodes Minibuffer File and Windows HOME. (And on MS Windows be sure to ...
user avatar
  • 69.7k
2 votes
Accepted

How to tweak dired-create-empty-file to facilitate the easy creation of files

You can write your own function and bind it to F7 instead of binding dired-create-empty-file to it - something like this (lightly tested): (defun my-dired-create-empty-file () (interactive) (let* ...
user avatar
  • 19.9k
2 votes

How to duplicate a file in Dired?

You can do this quite easily, and rather more flexibly, without defining any functions (and probably learning another way of using dired along the way). Mark the files you want to copy (if no files ...
user avatar
  • 143
2 votes

Modify the first element of the kill-ring

Mostly your problem was misplaces parens: too many ) here: (let ((tmp (car kill-ring)))) Use paren-mode to see which parens balances which parens. Standard function kill-new replaces the head of ...
user avatar
  • 69.7k
2 votes

Elisp function to open file name with space?

I recommend using call-process instead of shell-command: (defun open-a-file () (interactive) (call-process "xdg-open" nil 0 nil (read-file-name "Open: "))) One large ...
user avatar
  • 11.8k
2 votes

How to specify relative path to a file inside init.el

When your init file is loaded, the current directory, that is, the value of variable default-directory, is the directory where your init file is, by default. That is, that's the value unless your init ...
user avatar
  • 69.7k
2 votes
Accepted

How can I get the filename of the most recently modified PDF file in my temp directory?

(shell-command-to-string "ls -t /tmp/*.pdf | head -1")
user avatar
  • 11.8k
1 vote

Custom compilation command fails on Windows due to slashes in paths

Learn about backslashes in strings. And learn about manipulating file names. The result of evaluating this is presumably the absolute file name that you want for your program: (expand-file-name "...
user avatar
  • 69.7k
1 vote
Accepted

Help; how use Persistent Sets of Completion Candidates for search?

This answer is for using command icicle-find-file-absolute, which is similar in most regards to icicle-locate. But icicle-locate uses a prefix arg differently, passing it to system-command locate. ...
user avatar
  • 69.7k
1 vote

How do I set Icicles’s default sort order for filenames?

Updating this to provide the short answer, after email exchange: Set user option icicle-file-sort to the sort order you want, e.g., icicle-case-string-less-p. (Leaving the rest of the original ...
user avatar
  • 69.7k
1 vote
Accepted

Don't offer non-file-name as a file name in find-file

This comes from ffap (find file at point), as the name might suggest. Specifically, find-file uses read-file-name to read its input, which in turn calls read-file-name-default unless overridden ...
user avatar

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