浏览代码

Add WIP awk-preview

master
10sr 6 年前
父节点
当前提交
42e3b70fb5
签署人:: 10sr GPG 密钥 ID: 7BEC428194130EB2
共有 1 个文件被更改,包括 49 次插入0 次删除
  1. +49
    -0
      emacs.el

+ 49
- 0
emacs.el 查看文件

@@ -1506,4 +1506,53 @@ This mode is a simplified version of `adoc-mode'."
(add-to-list 'auto-mode-alist
'("\\.adoc\\'" . adoc-simple-mode)))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; awk-preview

(defgroup awk-preview nil
"Awk previewer."
:tag "Awk Preview"
:prefix "awk-preview-"
:group 'tools)

(defcustom awk-preview-program
(or (executable-find "gawk")
(executable-find "awk")
"awk")
"Awk program to execute."
:type 'string
:group 'awk-preview)

(defcustom awk-preview-switches
'("--sandbox" "--" "{print}")
"String of awk options appended when running awk preview."
:type '(repeat string)
:group 'awk-preview)

(defun awk-preview--invoke (start end output)
"Execute awk process and get result."
(let ((proc (apply 'start-process
"awk-preview"
output
awk-preview-program
awk-preview-switches)))
(message "%S" proc)
(process-send-region proc start end)
(process-send-eof proc)
(accept-process-output proc)
)
output)

(defun awk-preview (start end)
"Run awk and preview result."
(interactive "r")
(let ((output (with-current-buffer (get-buffer-create "*awk-preview output*")
(erase-buffer)
(current-buffer))))
(awk-preview--invoke start end output)
(message "awk-preview: %s" (with-current-buffer output
(buffer-substring-no-properties (point-min) (point-max))))
))

;;; emacs.el ends here

正在加载...
取消
保存