如何在emacs中快速打开文件? [英] How can I open quickly a file in emacs?

查看:105
本文介绍了如何在emacs中快速打开文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常复杂和密集的文件夹和文件结构。我想在emacs中快速打开一个离我家很远的文件。



Cx Cf 不够快,因为我必须写出可能很长的路径(例如: / very / long / and / boring / path / which / make / me / use / tab / for / autocompletion / too /much/and/ruins/my/hands/with/repetitive/strain/injuries/my_file_finally.tex



那么是另一个方式,更快,(比 Cx Cf )打开这样的文件,如果不是,有没有办法为最常用的文件创建快捷方式?



PS:我不想移动文件(长路径意味着我干净有组织的电脑)。

解决方案

选项#1 - 每个分配的键一个函数:

  -set-key(kbd< f6>)(lambda()(interactive)
(find-file/Users/HOME/.0.data/todo.org)
opened:%s(buffer-name))))






OPTION#2 - 具有选项的功能:

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

(defun lawlist-bookmark(choice)
选择目录和文件
(interactivec [D] [v] ocab.org | [g] td.org | [d] iary.org | [n] otes.org)
(cond
((eq choice?D)
(dired/ very / long / and / boring / path / which / make / me / use / tab / for / ...))
((eq choice?v)
(find-file/Users/HOME/.0.data/vocab.org)
(消息Opened:%s(buffer-name)))
((eq choice?g)
(find-file/Users/HOME/.0.data/gtd.org)
(消息Opened:%s(buffer-name)))
((eq选择?d)
(find-file/Users/HOME/.0.data/diary 。
(查找文件/Users/HOME/.0($)
((eq选择?n)

(消息Opened:%s(buffer-name)))
(t(messageQuit))))






选项#3 - 右键单击​​上下文菜单)

 (全局设置键[mouse-3]'法律列表弹出上下文菜单)

(defvar lawlist-cont ext-menu-map
(let((map(make-sparse-keymapContext Menu))
(定义键映射[find-file-todo](consToDo ()(interactive)
(find-file/Users/HOME/.0.data/todo.org))))
(define-key map [find-file-gtd](cons GTD(lambda()(interactive)
(find-file/Users/HOME/.0.data/gtd.org))))
(define-key map [find-file -notes](consNotes(lambda()(interactive)
(find-file/Users/HOME/.0.data/notes.org))))
(define-key map [find-file-vocab](consVocab(lambda()(interactive)
(find-file/Users/HOME/.0.data/vocab.org)))
(define-key map [find-file-diary](consDiary(lambda()(interactive)
(find-file/Users/HOME/.0.data/diary.org)) )
(define-key map [seperator-three]'(menu-item - ))
(define-key map [help-for-help](consHelp -for-help))
(定义键映射[seperator-two]'(菜单项 - ))
(define-key map [my-menu] LAWLIST(make-sparse-keymap我的菜单)))
(define-key map [my-menu 01](consNext Line'next-line))
(define- key map [my-menu 02](cons上一行的上一行))
(定义键映射[seperator-one]'(菜单项 - ))
map )

(defun lawlist-popup-context-menu(event& optional prefix)
弹出一个上下文菜单
(交互式@e \\\
P)
(define-key lawlist-context-menu-map [lawlist-major-mode-menu]
`(menu-item,(symbol-name major-模式)
,(mouse-menu-major-mode-map):visible t))
(弹出菜单法则列表 - 上下文菜单映射事件前缀))






选项#4 - 菜单栏下拉菜单:

 (require'easymenu)

(easy-menu-define lawlist-menu global-map我自己的菜单
(lawlist
[下一行下一行t]
[上一行previous-lin et
[Dired Modedired t]
[ - my-function t]
(Favorites
[Diary(find-file/用户/ HOME / .0.data / diary.org)]
[ - 日记]
[GTD(find-file/Users/HOME/.0.data/gtd .org]
[ - gtd]
[Vocab(查找文件/Users/HOME/.0.data/vocab.org)]
[ - vocab]
[Notes(find-file/Users/HOME/.0.data/notes.org)]
[ - 笔记]
[ToDo(find-file/Users/HOME/.0.data/todo.org)]
)))


I have a very complex and dense structure of folders and files. I would like to open a file which is very far away from my home quickly in emacs.

C-x C-f is not quick enough because I have to write the path which could be very long (example : /very/long/and/boring/path/which/make/me/use/tab/for/autocompletion/too/much/and/ruins/my/hands/with/repetitive/strain/injuries/my_file_finally.tex)

So, is it another way, quicker, (than C-x C-f) to open such file and, if not, is there a way to create shortcuts for the most used files ?

P-S : I don't want to move files (long paths means to me clean and organized computer).

解决方案

OPTION # 1 -- one function per assigned key:

(global-set-key (kbd "<f6>") (lambda () (interactive)
  (find-file "/Users/HOME/.0.data/todo.org")
  (message "Opened:  %s" (buffer-name))))


OPTION # 2 -- function with options:

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

(defun lawlist-bookmark (choice)
  "Choices for directories and files."
  (interactive "c[D]ired | [v]ocab.org | [g]td.org | [d]iary.org | [n]otes.org")
    (cond
           ((eq choice ?D)
           (dired "/very/long/and/boring/path/which/make/me/use/tab/for/..."))
           ((eq choice ?v)
           (find-file "/Users/HOME/.0.data/vocab.org")
            (message "Opened:  %s" (buffer-name)))
          ((eq choice ?g)
           (find-file "/Users/HOME/.0.data/gtd.org")
            (message "Opened:  %s" (buffer-name)))
          ((eq choice ?d)
           (find-file "/Users/HOME/.0.data/diary.org")
            (message "Opened:  %s" (buffer-name)))
          ((eq choice ?n)
           (find-file "/Users/HOME/.0.data/notes.org")
            (message "Opened:  %s" (buffer-name)))
          (t (message "Quit"))))


OPTION # 3 -- right click context menu (popup):

(global-set-key [mouse-3] 'lawlist-popup-context-menu)

(defvar lawlist-context-menu-map
  (let ((map (make-sparse-keymap "Context Menu")))
    (define-key map [find-file-todo] (cons "ToDo" (lambda () (interactive)
      (find-file "/Users/HOME/.0.data/todo.org"))))
    (define-key map [find-file-gtd] (cons "GTD" (lambda () (interactive)
      (find-file "/Users/HOME/.0.data/gtd.org"))))
    (define-key map [find-file-notes] (cons "Notes" (lambda () (interactive)
      (find-file "/Users/HOME/.0.data/notes.org"))))
    (define-key map [find-file-vocab] (cons "Vocab" (lambda () (interactive)
      (find-file "/Users/HOME/.0.data/vocab.org"))))
    (define-key map [find-file-diary] (cons "Diary" (lambda () (interactive)
      (find-file "/Users/HOME/.0.data/diary.org"))))
    (define-key map [seperator-three] '(menu-item "--"))
    (define-key map [help-for-help] (cons "Help" 'help-for-help))
    (define-key map [seperator-two] '(menu-item "--"))
    (define-key map [my-menu] (cons "LAWLIST" (make-sparse-keymap "My Menu")))
    (define-key map [my-menu 01] (cons "Next Line" 'next-line))
    (define-key map [my-menu 02] (cons "Previous Line" 'previous-line))
    (define-key map [seperator-one] '(menu-item "--"))
  map) "Keymap for the LAWLIST context menu.")

(defun lawlist-popup-context-menu  (event &optional prefix)
  "Popup a context menu."
  (interactive "@e \nP")
    (define-key lawlist-context-menu-map [lawlist-major-mode-menu]
      `(menu-item ,(symbol-name major-mode)
        ,(mouse-menu-major-mode-map) :visible t))
    (popup-menu lawlist-context-menu-map event prefix))


OPTION # 4 -- menubar drop-down menu:

(require 'easymenu)

(easy-menu-define lawlist-menu global-map "My own menu"
  '("lawlist"
    ["Next Line" next-line t]
    ["Previous Line" previous-line t]
    ["Dired Mode" dired t]
    ["--" my-function t]
    ("Favorites"
    ["Diary" (find-file "/Users/HOME/.0.data/diary.org")]
    ["--" diary]
    ["GTD" (find-file "/Users/HOME/.0.data/gtd.org")]
    ["--" gtd]
    ["Vocab" (find-file "/Users/HOME/.0.data/vocab.org")]
    ["--" vocab]
    ["Notes" (find-file "/Users/HOME/.0.data/notes.org")]
    ["--" notes]
    ["ToDo" (find-file "/Users/HOME/.0.data/todo.org")]
    )  ))

这篇关于如何在emacs中快速打开文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆