简体   繁体   English

如何实现“shell-command-on-region-to-string”emacs / elisp函数?

[英]How to implement 'shell-command-on-region-to-string' emacs/elisp function?

I need to get a range (or whole range) of current buffer, run program to process the range as an input, get the result and to put the string at the end of the current buffer. 我需要得到一个范围(或整个范围)的当前缓冲区,运行程序来处理作为输入的范围,得到结果并将字符串放在当前缓冲区的末尾。

I learned that shell-command-on-region can process a region. 我了解到shell-command-on-region可以处理一个区域。

I learned that shell-command-to-string can store the result of the program to a string. 我了解到shell-command-to-string可以将程序的结果存储到字符串中。

Then, how can I implement 'shell-command-on-region-to-string'? 那么,我该如何实现'shell-command-on-region-to-string'?

(defun shell-command-on-region-to-string (process &optional b e) 
  (interactive)
  (let ((b (if mark-active (min (point) (mark)) (point-min)))
        (e (if mark-active (max (point) (mark)) (point-max))))

  ?? (shell-command-on-region b e process (current-buffer) t)
  ?? how to store the return of a process to a string
  ?? how to insert the result at the end of current buffer
))
(defun shell-command-on-region-to-string (start end command)
  (with-output-to-string
    (shell-command-on-region start end command standard-output)))

(defun shell-command-on-region-with-output-to-end-of-buffer (start end command)
  (interactive
   (let ((command (read-shell-command "Shell command on region: ")))
     (if (use-region-p)
         (list (region-beginning) (region-end) command)
       (list (point-min) (point-max) command))))
  (save-excursion
    (goto-char (point-max))
    (insert (shell-command-on-region-to-string start end command))))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM