当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 6 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : [已解决]emacs格式化代码的问题
帖子发表于 : 2007-08-24 20:18 

注册: 2006-10-28 14:45
帖子: 9
送出感谢: 0 次
接收感谢: 0 次
请教高手,在emacs中编辑时我想调用外部命令格式化代码
(defun formatCode ()
(interactive)
(shell-command
(concat "d:/emacs/bin/a.exe \"" buffer-file-name "\""))
)

可是每次都是在新开的 *Shell Command Output* buffer中打开并显示格式化后的结果,有没有办法直接替换正在编辑的buffer,并且不要打开新的buffer


最后由 hugo222 编辑于 2007-08-26 14:15,总共编辑了 1 次

页首
 用户资料  
 
2 楼 
 文章标题 :
帖子发表于 : 2007-08-25 3:47 

注册: 2006-10-06 21:10
帖子: 57
送出感谢: 0 次
接收感谢: 0 次
C-h f shell-command RET
有output-buffer 参数

代码:
shell-command is an interactive compiled Lisp function in `simple.el'.
It is bound to M-!, <menu-bar> <tools> <shell>.
(shell-command command &optional output-buffer error-buffer)

Execute string command in inferior shell; display output, if any.
With prefix argument, insert the command's output at point.

If command ends in ampersand, execute it asynchronously.
The output appears in the buffer `*Async Shell Command*'.
That buffer is in shell mode.

Otherwise, command is executed synchronously.  The output appears in
the buffer `*Shell Command Output*'.  If the output is short enough to
display in the echo area (which is determined by the variables
`resize-mini-windows' and `max-mini-window-height'), it is shown
there, but it is nonetheless available in buffer `*Shell Command
Output*' even though that buffer is not automatically displayed.

To specify a coding system for converting non-ASCII characters
in the shell command output, use C-x RET c
before this command.

Noninteractive callers can specify coding systems by binding
`coding-system-for-read' and `coding-system-for-write'.

The optional second argument output-buffer, if non-nil,
says to put the output in some other buffer.
If output-buffer is a buffer or buffer name, put the output there.
If output-buffer is not a buffer and not nil,
insert output in current buffer.  (This cannot be done asynchronously.)
In either case, the output is inserted after point (leaving mark after it).

If the command terminates without error, but generates output,
and you did not specify "insert it in the current buffer",
the output can be displayed in the echo area or in its buffer.
If the output is short enough to display in the echo area
(determined by the variable `max-mini-window-height' if
`resize-mini-windows' is non-nil), it is shown there.  Otherwise,
the buffer containing the output is displayed.

If there is output and an error, and you did not specify "insert it
in the current buffer", a message about the error goes at the end
of the output.

If there is no output, or if output is inserted in the current buffer,
then `*Shell Command Output*' is deleted.


页首
 用户资料  
 
3 楼 
 文章标题 :
帖子发表于 : 2007-08-25 12:49 

注册: 2006-10-28 14:45
帖子: 9
送出感谢: 0 次
接收感谢: 0 次
谢谢二楼的,我试了一下,可能是对emacs实在不是太通,暂时只能将格式化后的代码插入到光标所在的位置,命令如下

(defun formatCode ()
(interactive)
(shell-command
(concat "d:/emacs/bin/a.exe \"" buffer-file-name "\"")
2 nil)
)


页首
 用户资料  
 
4 楼 
 文章标题 :
帖子发表于 : 2007-08-25 12:51 

注册: 2006-10-28 14:45
帖子: 9
送出感谢: 0 次
接收感谢: 0 次
代码:
The optional second argument output-buffer, if non-nil,
says to put the output in some other buffer.
If output-buffer is a buffer or buffer name, put the output there.
If output-buffer is not a buffer and not nil,
insert output in current buffer.  (This cannot be done asynchronously.)
In either case, the output is inserted after point (leaving mark after it).


一个是在新buffer中打开,另一个是插入当前的buffer,我需要替换,有谁能再提示下


页首
 用户资料  
 
5 楼 
 文章标题 :
帖子发表于 : 2007-08-25 22:02 

注册: 2006-10-06 21:10
帖子: 57
送出感谢: 0 次
接收感谢: 0 次
呵呵,没有注意你的目的。
看看shell-command-on-region 命令。

M-| runs the command shell-command-on-region
which is an interactive compiled Lisp function in `simple.el'.
It is bound to M-|, <menu-bar> <tools> <shell-on-region>.
(shell-command-on-region start end command &optional output-buffer
replace error-buffer display-error-buffer)


页首
 用户资料  
 
6 楼 
 文章标题 :
帖子发表于 : 2007-08-25 23:59 

注册: 2006-10-28 14:45
帖子: 9
送出感谢: 0 次
接收感谢: 0 次
哈哈,终于可以了,谢谢forcotton兄
代码:
(defun formatCode ()
(interactive)
(shell-command-on-region (point-min) (point-max)
(concat "d:/emacs/bin/a.exe \"" buffer-file-name "\"")
 nil t
)
)

;; (region-beginning) (region-end) 只替换选择部分
;; (point-min) (point-max)   全部替换


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 6 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 3 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译