通过参数列表移动

ele*_*kil 3 emacs elisp cc-mode

我使用由一个安装一个C++程序员cc-modeCEDET,当然还有我们敬爱的emacs(v24.2).

我缺少的一个功能是一个通过参数列表快速移动点的函数.考虑这个例子:

void takesManyArgs( int a1, int a2, int a3, std::pair<int,int> a4, int a5 ){  
    // does something nifty!  
}  
// [...]
takesManyArgs( b1, b2, b3, make_pair( b4, b5 ), b6 );
Run Code Online (Sandbox Code Playgroud)

点在第一个之前int.现在我想以一种简单的方法快速浏览参数列表,即在第一个非空格字符超过逗号(参数分隔符)之前移动的forward-argument(和backward-argumentaswell)函数.
我已经编写了一个小功能,但它不是我喜欢它的工作方式:

(defun arg-forward ()  
  "Move point forward in the file until we hit an argument separator, i.e. comma, colon or semicolon."  
  (interactive)  
  (progn  
    (re-search-forward "[,]")))  
Run Code Online (Sandbox Code Playgroud)

原则上这个函数只是跳转到下一个逗号.那不是我想要的行为.

我想要一个功能:

  • 编辑:跳转到下一个参数分隔符(即C++的逗号)并在该参数分隔符后面放置点
  • 检查逗号后面是否有空格; 万一有一个点移动到第一个非空白字符(即,而不是,| int它看起来像, |int这里|的标记点)
  • 停止在参数列表的末尾并打印一条消息(例如"在参数列表末尾")
  • 它的"范围"内,即停留它会从去|int b3|make_pair( int b4, int b5 )|int a6地方|的标记点

任何帮助你elisp"黑客"表示赞赏!

编辑:添加了一些说明.
Edit2:修复了示例"代码"

Tre*_*son 5

此功能似乎按您的要求执行:

(defun arg-forward ()
  "Move point forward until we hit an argument separator, the comma, colon, semicolon"
  (interactive)
  (condition-case nil
      (let ((separator-regexp "[,:;]"))
        (forward-sexp)
        (while (not (or (looking-at (format "[ \t]*%s" separator-regexp))
                        (save-excursion (forward-char -1)
                                        (looking-at (format "[]\"')}]*[ \t]*%s " separator-regexp)))))
          (forward-sexp))
        (if (looking-at separator-regexp)
            (forward-char 1))
        ;; going forward one sexp and back puts point at front of sexp
        ;; essentially skipping the whitespace, but also ensuring we don't
        ;; jump out of a larger closing set of parentheses 
        (forward-sexp)
        (forward-sexp -1))
    (error
     (beep)
     (message "At end of argument list"))))
Run Code Online (Sandbox Code Playgroud)