Sometime, we need to open a file or buffer which name begin 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 (aborn.jiang@foxmail.com)
;; 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的更多相关文章

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

    在用emacs看代码的时候,在文件间跳来跳去,如果工程太大的话,很可能会有重名文件,这个时候, 你就不知道自己在什么的地方了.需要一个查看当前正在编辑区的文件的名字的方法. emacs在这个地方,存储 ...

  2. linux 下 Emacs dired 模式 隐藏 dot file ".filename" 文件

    有时候 emacs 下调用 C-x dired 是挺方便的一个事,但是一堆的点文件(linux下以"."为前缀的文件,即隐藏文件)让人目不暇接,打算隐藏之. 参考如下: 最主要的是 ...

  3. 关于之前玩emacs记的些笔记

    移动 C-v 向前翻页 M-v 向后翻页 C-l 当前行居中显示 继续按会依次到上,下,中   C-x C-c 退出 C-g    退出一个正在运行的命令,还可以取消数字参数和只输入到一半的命令   ...

  4. emacs 操作集锦

    1.C-k 的功能并不是剪切当前行,而是剪切当前行从光标到行末的内容. Emacs 中的剪切不叫剪切(cut),叫kill,复制(copy)不叫copy ,叫kill-ring-save (这个可以理 ...

  5. Emacs Lisp 功能扩展集锦

    http://docs.huihoo.com/homepage/shredderyin/emacs_elisp.html Emacs 具有超强的扩展性.这是当今没有任何其它编辑器可以比拟 的强大特点. ...

  6. GNU Emacs命令速查表

    GNU Emacs命令速查表 第一章  Emacs的基本概念 表1-1:Emacs编辑器的主模式 模式 功能 基本模式(fundamental mode) 默认模式,无特殊行为 文本模式(text m ...

  7. NASM mode for Emacs

    NASM mode for Emacs   Quick post for those Emacs users out there.   The common assembler used on GNU ...

  8. Emacs 快速指南(中文翻译)

      Emacs 快速指南 目录 1. 小结(SUMMARY) 2. 基本的光标控制(BASIC CURSOR CONTROL) 3. 如果 EMACS 失去响应(IF EMACS STOPS RESP ...

  9. Emacs快速入门

    Emacs 快速入门 Emacs 启动: 直接打emacs, 如果有X-windows就会开视窗. 如果不想用X 的版本, 就用 emacs -nw (No windows)起动. 符号说明 C-X ...

随机推荐

  1. C语言cgi(1)

    1Columbia Universitycs3157 – Advanced ProgrammingSummer 2014, Lab #2, 60ish pointsJune 9, 2014Follow ...

  2. 【网络可靠版】Extjs4 Treegrid 使用实例

    最近调试EXTJS 4的treegrid实例,看了很多水友的文章,以及官方的demo, 没一个可靠的,全都无法显示出来.像对于我们习惯用C++的coder来说,EXTJS简直就是一群无政府土匪来维护的 ...

  3. IOS私人API用法

    先要使用class-dump 和dumpFrameworks.pl 工具 将ios的framework导出来. 下面是工具的下载地址: class-dump下载地址http://www.codethe ...

  4. 使用Spring的@Autowired 实现DAO, Service, Controller三层的注入(转)

    简述: 结合Spring和Hibernate进行开发 使用@Autowired实现依赖注入, 实现一个学生注册的功能,做一个技术原型 从DAO(Repository) -> Service -& ...

  5. 在VC/MFC中嵌入Google地图——图文并茂

    近期须要实验室须要将在无人机地面站中嵌入地图,在网上找了非常多资料,最终有些眉目了, 首先.做这个须要用到的知识有.MFC控件.MFC类库.JavaScript脚本语言.Google API.Goog ...

  6. Enum变量值的Discretion

    有些时候,某个方法的返回值是个枚举类型,比如描述登录结果: public enum LoginResult { Success, WrongPassword, } 当前段UI获取到登陆方法的返回结果时 ...

  7. 乐在其中设计模式(C#) - 备忘录模式(Memento Pattern)

    原文:乐在其中设计模式(C#) - 备忘录模式(Memento Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 备忘录模式(Memento Pattern) 作者:webabc ...

  8. MongoDB学习笔记-命令

    连接数据库: mongodb://账号:密码@IP/库名 更多方式参考:http://www.runoob.com/mongodb/mongodb-connections.html 命令整理: 名称 ...

  9. Cocos2d-x学习笔记(9)(CCTextFieldTTF使用输入框)

    1.CCTextFieldTTF创建和使用 CCTextFieldTTF::create(const char* placeholder,const char* fontName.float font ...

  10. 【剑指offer】第一个字符只出现一次

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/27106997 题目描写叙述: 在一个字符串(1<=字符串长度<=10000,所 ...