Emacs 源文件 头文件 切换

1.今天试着写了下Emacs中头文件与源文件切换的lisp程序,发现还有好多内容没有看到,写了一点,等忙完了这阵子好好补全

下面是一些内容,记录下

;;得到当前的文件名(不包含扩展名)                                               
(file-relative-name (file-name-sans-extension buffer-file-name))
;;得到当前文件的路径名                                                          
(file-name-directory buffer-file-name)

(string-match "/" "/root/osg/src/osgDB")


;;分割路径(还有问题)                                                            
(let ((start 0) (listdic))
  (while (string-match "/" "/root/osg/src/osgDB/" start)
    (princ (format "find at %d\n" (match-beginning 0)))
    (setq listdic (list  listdic (match-beginning 0)))
    (setq start (match-end 0)))
  (while listdic
    (print (car listdic))
    (setq listdic (cdr listdic)))
    )


下面是补充

;;;;------------------------------------------------------------------------------------------------------------------------------------------------

换了一下方式,切换目录的工作交给了c++ 来做,如下

下面这些约束方式可以根据实际情况自己写,我是用来阅读源码时候用的,头文件在include 中 ,源文件在src中

代码的意思是:给定一个文件的路径,判断时候为头文件还是源文件,然后直接转换成对应的目录下

#include <iostream>
#include <cstring>
using namespace std;
string parse(string path)
{
  long long   begin=path.find("include");
  if(begin!=string::npos){//头文件
     path=path.replace(begin,sizeof("include")-1,"src")+".cpp";
  }
  else if(( begin=path.find("src"))!=string::npos) {
    path=path.replace(begin,sizeof("src")-1,"include");
    begin=path.find_last_of('.');
    path=path.replace(begin,4,"");
  }
  return path;
}
int main(int argc, char *argv[])
{
  cout<<parse(argv[1]);// 外部传参
  return 0;
}

在.emacs 配置文件中(我把上段代码编译成了可执行文件 Switching (   Switching 后有个空格  csdn的排版真差劲!!!,老出现莫名奇妙的问题 ) ,放到环境变量中,

 
(defun Switching()
  (interactive)
  (find-file
   (shell-command-to-string
    (concat "Switching "
            (file-truename buffer-file-name)))))
(global-set-key [(f10)] 'Switching)




  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值