Directory faster ways in emacs buffer

So I asked this question concerning directory faster ways in a covering. The suggestion is I would certainly such as to have the ability to open a documents in /home/Documents/foo, claim, by keying C-x C-f ~foo/file.

So, exists a means to mimic zsh's "called directory sites" in the emacs barrier?

By the way, the faster way interpretations I intend to make use of are currently in my.zshrc, if there's a remedy that reviews them straight, that obtains incentive factors.

2019-05-04 12:59:50
Source Share
Answers: 1

The Emacs part that's liable for increasing ~ in documents names is expand-file-name. However, it's created in C, and also deep inside its bowels is code that thinks that what follows ~ is a customer name. The good news is, Emacs has a common means of including a wrapper around features, so you can do what you desire if you do not mind duplicating several of the reasoning in the integrated function.

Below's some entirely untried code that needs to get you going. Seek out "Advising Emacs Lisp Functions" in the Emacs Lisp guidebook for additional information ; the keynote is that defadvice includes some code to run prior to the real code of expand-file-name. Please signify the blunders I've certainly made in remarks (whether you recognize just how to repair them or otherwise).

(ad-define-subr-args 'expand-file-name '(name &optional default-directory))
(defvar expand-file-name-custom-tilde-alist
  '("foo" . "/home/Documents/foo"))
(defadvice expand-file-name (before expand-file-name-custom-tilde
                             activate compile)
  "User-defined expansions for ~NAME in file names."
    (if (string-match "\\`\\(\\(.*/\\)?~\\([^:/]+\\)\\)/" name)
        (let ((replacement (assoc (match-string 2 name) expand-file-name )))
          (if replacement
              (setq name (replace-match replacement t t name 1)))))))

I'll leave analyzing the faster ways in .zshrc to load expand-file-name-custom-tilde-alist (or whatever strategy you pick to maintain the pen names in synch) as a workout.

2019-05-08 01:58:35