在Emacs中编写Haskell代码时,我经常会遇到我想要改变的情况:
(foo, [])
进入
([], foo)
如果Emacs将[]
识别为单词,那么我可以M-t
使用transpose-words
并切换它们。是否有可能以不破坏其他功能的方式实现这一目标?
答案 0 :(得分:5)
您需要C-M-t
,它运行命令transpose-sexps
。
有很多命令以C-M-
开头,运行s-exp命令而不是类似的基于单词的命令,例如C-M-f
/ C-M-b
,s-exp前进/后退
此外,还有emacs.SE的Emacs Stack Exchange。
答案 1 :(得分:0)
(defun my-transpose-function-args ()
"Assumes to be called between arguments. "
(interactive "*")
(let* ((orig (point))
(end1 (progn (skip-chars-backward " \t\r\n\f,")
(point)))
(beg1
(progn
(skip-chars-backward "^ \t\r\n\f,(")
(point)))
(string1 (buffer-substring beg1 end1))
(beg2 (copy-marker
(progn (goto-char orig)
(skip-chars-forward " \t\r\n\f")
(point))))
(end2 (copy-marker
(progn (skip-chars-forward "^ \t\r\n\f,)")
(point))))
(string2 (buffer-substring beg2 end2)))
(goto-char beg1)
(delete-region beg1 end1)
(insert string2)
(goto-char beg2)
(delete-region beg2 end2)
(insert string1)))