5

我想在emacs中缩写路径。

emacs 的标准行为是: Cx Cf 然后排版文件的完整名称。例如

C-x C-f ~/latex/project/style/test.sty

可用于快速完成路径。

由于我经常使用三个目录中的两个,我想知道是否可以提供一些“缩写路径”。例如

C-x C-f lstyle/test.sty

在 « ~/latex/project/style/test.sty»中自动展开

感谢您的任何帮助 !

4

7 回答 7

3

还没有提到的东西,但这只是另一个机会(在 vanilla Emacs 中,不需要使用 Helm 或 IDO)。你可以使用书签。特别是对于打开文件,您将C-x r m- 创建一个书签(系统将提示您为该书签指定一个名称),然后C-x r b稍后调用该书签(将提示您输入您之前为该书签指定的名称)。

如果您对路径的主要用途是打开文件,这将为您节省一些输入,但如果您需要将其作为文本插入,那么它不会替换缩写。

如果你不知道,也许还有一件事。输入路径后,C-x C-f您可以使用:

  1. C-x C-fM-pM-n浏览您打开和向下打开的文件的历史记录。

  2. C-x C-fM-r通过为其提供正则表达式来搜索历史记录(尽管有一个缺点,当您键入正则表达式时,您不会看到它将进行的匹配)。

于 2013-09-26T22:28:49.273 回答
2

使用标准选项directory-abbrev-alist。从文档字符串:

Alist of abbreviations for file directories.
A list of elements of the form (FROM . TO), each meaning to replace
FROM with TO when it appears in a directory name.  This replacement is
done when setting up the default directory of a newly visited file.

FROM is matched against directory names anchored at the first
character, so it should start with a "\\`", or, if directory
names cannot have embedded newlines, with a "^".

FROM and TO should be equivalent names, which refer to the
same directory.  Do not use `~' in the TO strings;
they should be ordinary absolute directory names.

Use this feature when you have directories which you normally refer to
via absolute symbolic links.  Make TO the name of the link, and FROM
the name it is linked to.
于 2013-09-27T00:50:29.447 回答
2

实现这一目标的最佳方法是使用缩写。它们是简短的单词,在键入时会扩展为任何内容(因此,只要您点击“/”或空格或某些标点符号,扩展就会发生)。

将以下内容添加到您的~/.emacs文件或~/.emacs.d/init.el文件中(我更喜欢第二个):

(setq-default abbrev-mode t)
(define-abbrev global-abbrev-table "lstyle" "~/latex/project/style")

然后试一试,在任何地方输入“lstyle/”,它会扩展为“~/latex/project/style”。

于 2013-09-26T19:31:44.107 回答
1

不完全符合您的要求,但您可以将recentfmode 与idomode 结合使用来快速访问您最近打开的文件。将此代码放入您的初始化文件中:

;; ido-mode
(ido-mode t)

;; recent mode
(recentf-mode 1)

;; define a function to use recentf from ido
(defun recentf-ido-find-file ()
  "Open a recent file using IDO mode"
  (interactive)
  (let ((file (ido-completing-read "Recent file: " recentf-list nil t)))
    (when file
      (find-file file))))

(global-set-key (kbd "C-c f") 'recentf-ido-find-file)

然后您可以按C-c f以非常快速地打开您最近的文件。

于 2013-09-26T19:56:23.857 回答
0

对于这样的事情有几种解决方案。很难提前说你会更喜欢哪一个。

一种流行的方法是使用 ido(参见此处此处),其他方法是 helm。

于 2013-09-26T15:24:13.240 回答
0

在寻找同一问题的答案时,我发现了以下示例

(定义缩写表'我的缩写表
  '(("xy" "/path/to/the/directory")))

(添加钩子
 'minibuffer-setup-hook
 (拉姆达()
   (缩写模式 1)
   (setq local-abbrev-table my-abbrev-table)))

(defadvice minibuffer-complete
  (在 my-minibuffer-complete 激活之前)
  (扩展缩写))

;; 如果您使用部分完成模式
(defadvice PC-do-completion
  (在 my-PC-do-completion 激活之前)
  (扩展缩写))
于 2014-10-16T17:03:10.777 回答
0

使用答案作为参考:

(global-set-key (kbd "<f5>") 'lawlist-bookmark)

(defun lawlist-bookmark (choice)
  "Choices for directories and files."
  (interactive "c[d]ropbox | [b]oxsync")
    (cond
     ((eq choice ?d)
      (interactive)
      (counsel-find-file "C:/Users/acer/Dropbox/"))
     ((eq choice ?b)
      (counsel-find-file "C:/Users/acer/Box Sync/"))
     (t (message "Quit"))))

这里counsel-find-file被用来代替find-file允许在迷你缓冲区中进行交互式浏览。

于 2019-12-24T07:18:06.433 回答