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. 设备Oracle当误差:环境不符合要求》》解决方法

    一旦安装Oracle当我常常会遇到这样的问题.也没太在意,改了一下client\stage\cvu文件夹cvu_prereq.xml档(添加支持目前的操作系统信息)为了克服,我没有做笔记,但后来有同学 ...

  2. MVC 学习 区域

    http://www.cnblogs.com/fly_dragon/archive/2011/10/12/2209438.html

  3. hdu1561(树形背包)

    给定n,m表示n个城堡,我们可以选择攻占m个城堡.要使得价值最大 接下来n行 a b,   第i行的a b,表示攻占第i个城堡的价值为b,但需要先攻占第a个城堡 如果有多个a=0的点,那么就不是一棵树 ...

  4. mysql寻呼最快

    大家都知道,mysql分页写: select * from 'yourtable' limit start,rows 如今我数据库一张表里面有9969W条数据.表名叫tweet_data select ...

  5. 《深入Java虚拟机》笔记:指令集 (转)

    <深入Java虚拟机>笔记:指令集   指令 含义 iconst_m1 把int型常量-1压入栈中 iconst_0 把int型常量压入栈中 fconst_1 把float型常量1压入栈中 ...

  6. ios 仿新浪微博 UINavigationController 向左滑动时显示上一个控制器的View.

    仿新浪微博 UINavigationController 向左滑动时显示上一个控制器的View. 实现原理,UINavigationController 的 self.view显示时把当前显示的vie ...

  7. centos7 设备 mariadb-10

    下载地址: http://mirrors.ustc.edu.cn/mariadb/mariadb-10.0.19/source/mariadb-10.0.19.tar.gz 由于用cmake所以线安装 ...

  8. C#读书

    C#读书雷达   大家都知道,ThoughtWorks的技术雷达每年都会发布两到三次,它不但是业界技术趋势的标杆,更提供了一种卓有成效的方法论,即打造自己的技术雷达.在这种思想的驱动下,我们诞生了自己 ...

  9. Zookeeper分享

    Zookeeper: 是一个分布式的,为分布式应用提供数据一致性服务的程序. Zookeeper是怎么来的? 分布式系统:是一个硬件或软件组件分布在不同的网络计算机上,彼此之间仅仅通过消息传递进行通信 ...

  10. android最新的工具DateHelper

    最新的工具DateHelper 实用程序类,.的天数来获得一个给定的月份.过了几天去习惯或.周.一个月.日期等.. 代码例如以下: import android.annotation.Suppress ...