• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

[emacs][delphi]跳到函数声明/实现

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
唉,emacs用久了,觉得别的编辑器都不给力,觉得delphi自己的编辑器实在是难用。但emacs里面又没有那些语法相关的功能(尤其是pascal/delphi,似乎网上找不到多少相关的配置),于是两边来回切换着用,蛋疼啊。
 
中午没睡觉,自己写了两个elisp函数来jump to declaration/implementation,原型倒是很快,但为适应各种情况却调试了一个小时。
 
可用于delphi-mode和pascal-mode 。缺省配到了跟Delphi里面缺省快捷键一致的Ctrl-Shift-up和Ctrl-Shift-down上。
 
(delphi 的快捷键不能自定义实在是很挫,跟 emacs 交叉使用也是蛋疼的办法,我还是找xkeymacs的代码调试一下看看它为啥不工作吧)
 
(defun delphi-jump-to-declaration ()
  (interactive)
  (let ( (pt (ignore-errors
               (save-excursion
        (end-of-line)
        (re-search-backward "^\\(procedure\\|function\\|constructor\\|destructor\\)[ \t]+\\([_a-zA-Z][_a-zA-Z0-9]*\\>\\)?\\.?\\([_a-zA-Z][_a-zA-Z0-9]*\\)")
        (let ( (method-type  (match-string-no-properties 1)) 
               (class-name   (if (match-string 3) (match-string-no-properties 2) "" ))
               (func-name    (or (match-string-no-properties 3) (match-string-no-properties 2))) )
          (beginning-of-buffer)
          (if (> (length class-name) 0)
              (re-search-forward (format "%s[ \t]+=" class-name)))
          (when (re-search-forward (format "%s[ \t]+%s\\>" method-type func-name))
              (backward-word)
              (point)))))) )
    (when pt (goto-char pt))))
      

(defun delphi-jump-to-implementaion()
  (interactive)
  (let ( (pt (ignore-errors
               (beginning-of-line)
               (when (re-search-forward "\\(procedure\\|function\\|constructor\\|destructor\\)[ \\t]+\\([_a-zA-Z][_a-zA-Z0-9]*\\)")
                 (let ( (method-type  (match-string-no-properties 1))  ;;procedure/function/constructor
                        (func-name    (match-string-no-properties 2))
                        type-name
                        type-type)
                   (when (re-search-backward "\\<\\([_a-zA-Z][_a-zA-Z0-9]*\\)[ \\t]*=[ \\t]*\\(class\\|interface\\)")
                     (setq type-name (match-string-no-properties 1))
                     (setq type-type (match-string-no-properties 2)))
                   (if (string= type-type "interface")
                       (error "interface has no implementation part: %s" type-name)
                     (progn
                       (re-search-forward "^implementation\\>" nil t)
                       ;;(message "%s|%s|%s" method-type type-name func-name)
                       (if type-name
                           (re-search-forward (format "%s[ \\t]+%s\\.[ \\t]?%s\\>" method-type type-name func-name))
                         (re-search-forward (format "%s[ \\t]+%s\\>" method-type func-name))))))))) )
    (when pt (progn
	       (goto-char pt)
	       (beginning-of-line)))))
			

(define-key delphi-mode-map (kbd "<C-S-up>") 'delphi-jump-to-declaration)
(define-key delphi-mode-map (kbd "<C-S-down>") 'delphi-jump-to-implementaion)

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
MATLAB-基本信号处理发布时间:2022-07-18
下一篇:
数字信号处理MATLAB简单序列发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap