【求助 & 讨论】快速将选区内容添加到文件?

各位大佬好,

目前有这么一个需求,快速将选区中的内容添加到同一文件的末尾,要求每次添加的内容都在新的一行!自己勉强糊了一个丑陋的函数,请教各位大佬有无现成方案替代或可否改进下面这个函数的实现?

(defun test ()
  (interactive)
  (append-to-file (region-beginning) (region-end) "~/test.txt")
  (append-to-file "\n" nil "~/test.txt"))
(global-set-key [f8] 'test)

可以用 org-capture

(add-to-list 'org-capture-templates
             '("j" "test" plain (file "/path/file")
               "%i"))
2 个赞

你的函数挺好的,没啥需要改进的。我大概会写成(风格略微差别):

(defun test (beg end)
  (interactive "r")
  (write-region
   (concat (buffer-substring beg end) "\n") nil "~/test.txt" 'append))