emacs quick open and jump file (or buffer) which name is current word

Sometime, we need to open a file or buffer which name began with current word in emacs.

Here I give the solution as follows.

;; -----------------------------------------------------------------------------
;; quick-file-jump.el
;; Why this module?
;;     Sometimes, we need to open a file or buffer which name
;;            began with current word in emacs.
;;     Here is the solution.
;;
;; Install.
;;   put this file (quick-file-jump.el) in your load path and
;;   add follow codes into your initial emacs files (.emacs or init.el)
;;   (require ‘quick-file-jump)
;;   (global-set-key (kbd "<M-return>") ‘ab/quick-buffer-jump)
;;
;; Author:
;;   Aborn Jiang ([email protected])
;;   2014-05-13
;; -----------------------------------------------------------------------------

(provide ‘quick-file-jump)
(defun ab/quick-buffer-jump ()
  "Quickly jump to buffer/file which name is current word"
  (interactive)
  (setq fname (current-word))
  (setq blist (buffer-list))
  (setq status nil)
  (setq switchedbuffer "nil")
  (dolist (value blist)
    (when (and (bufferp value)
               (buffer-file-name value)
               (not status)
               (string-match (concat "^" (regexp-quote fname))
                             (buffer-name value)))
      (progn (switch-to-buffer (buffer-name value))
             (setq status t)
             (setq switchedbuffer (buffer-name value)))
      ))
  (if status                     ;; success search in buffer list.
      (message "skip to %s buffer" switchedbuffer)
    (ab/quick-file-jump)))       ;; find files in current path.

(defun ab/quick-file-jump ()
  "Quickly open and jump file with name begin with current word"
  (interactive)
  (setq fname (current-word))
  (setq switchedfile "nil")
  (setq dflist (directory-files (ab/get-current-path)))
  (dolist (value dflist)
    (when (and (file-regular-p value)
               (string-match
                (concat "^" (regexp-quote fname)) value))
      (find-file value)
      (setq switchedfile value)
      (setq status t)))
  (if status                     ;; success search in file list
      (message "open and skip to %s file." switchedfile)
    (message "not find file name begin %s" fname)))

(defun ab/get-current-path ()
  "Get the current path"
  (interactive)
  (message (file-name-directory (buffer-file-name))))

;; default global key setting
(global-set-key (kbd "<M-return>") ‘ab/quick-buffer-jump)

emacs quick open and jump file (or buffer) which name is current word

时间: 2024-11-10 20:51:10

emacs quick open and jump file (or buffer) which name is current word的相关文章

[daily] emacs显示file name buffer的全路径

在用emacs看代码的时候,在文件间跳来跳去,如果工程太大的话,很可能会有重名文件,这个时候, 你就不知道自己在什么的地方了.需要一个查看当前正在编辑区的文件的名字的方法. emacs在这个地方,存储这个名字.是变量 buffer-file-name 从我由low到不low的实践过程,有以下方法可以查看: 1.  用help查看变量的值 C-h v + buffer-file-name 2. 直接在mini buffer里eval该变量 M-: + buffer-file-name 3. 把全路

Emacs Commands List

C = ControlM = Meta = Alt|Esc BasicsC-x C-f?"find" file i.e. open/create a file in bufferC-x C-s?save the fileC-x C-w?write the text to an alternate nameC-x C-v?find alternate fileC-x i?insert file at cursor positionC-x b?create/switch buffersC-

GNU Emacs命令速查表

GNU Emacs命令速查表 第一章  Emacs的基本概念 表1-1:Emacs编辑器的主模式 模式 功能 基本模式(fundamental mode) 默认模式,无特殊行为 文本模式(text mode) 书写文字材料(第二章) 邮件模式(mail mode) 书写电子邮件消息(第六章) RMAIL模式(RMAIL mode) 阅读和组织电子邮件(第六章) 只读模式(view mode) 查看文件,但不进行编辑(第五章) shell模式(shell mode) 在Emacs里运行一个UNIX

emacs搭建web开发环境

web-mode web mode website About web-mode.el is an autonomous emacs major-mode for editing web templates. HTML documents can embed parts (CSS / JavaScript) and blocks (client / server side). Download web-mode.el Install (require 'web-mode) (add-to-lis

File System Design Case Studies

SRC=http://www.cs.rutgers.edu/~pxk/416/notes/13-fs-studies.html Paul Krzyzanowski April 24, 2014 Introduction We've studied various approaches to file system design. Now we'll look at some real file systems to explore the approaches that were taken i

Emacs 快速指南 - 原生中文手册

Emacs 快速指南 -折叠目录 1. 小结(SUMMARY) 2. 基本的光标控制(BASIC CURSOR CONTROL) 3. 如果 EMACS 失去响应(IF EMACS STOPS RESPONDING) 4. 被禁用的命令(DISABLED COMMANDS) 5. 窗格(WINDOWS) 6. 插入与删除(INSERTING AND DELETING) 7. 撤销(UNDO) 8. 文件(FILE) 9. 缓冲区(BUFFER) 10. 命令集扩展(EXTENDING THE C

Emacs 快速指南(中文翻译)

Emacs 快速指南 目录 1. 小结(SUMMARY) 2. 基本的光标控制(BASIC CURSOR CONTROL) 3. 如果 EMACS 失去响应(IF EMACS STOPS RESPONDING) 4. 被禁用的命令(DISABLED COMMANDS) 5. 窗格(WINDOWS) 6. 插入与删除(INSERTING AND DELETING) 7. 撤销(UNDO) 8. 文件(FILE) 9. 缓冲区(BUFFER) 10. 命令集扩展(EXTENDING THE COMM

Emacs 显示行数

分享一下我老师大神的人工智能教程吧.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net Emacs需要第三方插件显示行号 1  下载 linum.el 2  复制 linum.el 到“/usr/share/emacs/site-lisp/”或者其他 load-path路径下 3  配置 linum.el 到 ~/.emacs(自动创建 .emacs:启动emacs,用鼠标点击Options菜单,随便点击一两个选项,比

成为Emacs高手01-学习自带教程

Emacs 快速指南. [注意:位于[]之间的内容是译注,比如本行,下同.] Emacs 键盘命令通常包含 CONTROL 键(有时候以 CTRL 或 CTL 来标示)和META 键(有时候用 EDIT 或 ALT 来标示).为了避免每次都要写出全名,我们约定使用下述缩写: C-<chr>  表示当输入字符 <chr> 时按住 CONTROL 键. 因此 C-f 就表示:按住 CONTROL 键再输入 f. M-<chr>  表示当输入字符 <chr> 时按