2016-02-29 47 views
1

我有一個emacs外殼緩衝區,並希望將我輸入的每個命令都作爲新的文本行保存在新的臨時緩衝區中。將emacs外殼輸入列表複製到緩衝區或文件

我的殼歷史是一樣的東西:

% echo 1 
% echo 2 

我發現comint-dynamic-list-input-ring其中包含的命令,但它是在一個反向排序表像這樣

echo2  echo1 

我需要一個前鋒排序時間列表,理想情況下在一個臨時緩衝區,所以我可以編輯緩衝區並保存到.bash文件或你有什麼。

回答

1

我想你應該設置comint-input-ring-file-name和使用comint-write-input-ring保存您的命令:

(defun my-shell-buffers() 
    "Return the list of buffers with non-nil `comint-input-ring'." 
    (let (ret) 
    (dolist (b (buffer-list) ret) 
     (with-current-buffer b 
     (when comint-input-ring 
      (push (buffer-name b) ret)))))) 
(defun my-edit-history (comint-buffer history-file) 
    (interactive 
    (list (completing-read "Comint buffer: " 
          (or (my-shell-buffers) 
           (error "No shell buffers")) 
          nil t nil nil 
          (and comint-input-ring (buffer-name))) 
     (read-file-name "History file name: "))) 
    (with-current-buffer comint-buffer 
    (let ((comint-input-ring-file-name history-file)) 
     (comint-write-input-ring) 
     (find-file comint-input-ring-file-name)))) 
+0

非常好,我可以創建一個小自定義函數來提示輸入文件名,保存輸入環,然後在緩衝區中找到該文件進行編輯。 – blokeley

1

感謝這麼多的@sds

只是爲了記錄在案,我自己的最新版本是:

(defun write-input-ring (filename) 
    "Write shell input to FILENAME then visit FILENAME." 
    (interactive "F") 
    (let ((comint-input-ring-file-name filename)) 
    (comint-write-input-ring)) 

    (if (file-readable-p filename) 
     ;; If the input ring was saved to a file, visit that file 
     (find-file filename) 
    ;; Else report that no input was saved 
    (message "This buffer has no shell history."))) 
+0

當你在非'comint'緩衝區中調用它時,你期望它做什麼? – sds

+0

我想也許它可以'(消息「這個緩衝區沒有外殼歷史」)。不過,我喜歡現在的解決方案,它工作的很好,所以我只是好奇它是如何完成的。非常感謝你指出昨天的前進方向。 – blokeley

+0

看到我最新的代碼改進 – sds