简体   繁体   English

当emacs * scratch *缓冲区打开时自动粘贴剪贴板内容

[英]Auto paste clipboard contents when emacs *scratch* buffer opens

Most of the time when I open emacs without arguments it's to manipulate the clipboard contents. 在大多数情况下,当我不带参数打开emacs时,就是要操作剪贴板内容。 So I would like emacs to start and display directly the clipboard contents in the *scratch* buffer that opens. 因此,我希望emacs启动并直接在打开的* scratch *缓冲区中显示剪贴板内容。

I added this to my .emacs, seems to do the job : 我将其添加到我的.emacs中,似乎可以完成此工作:

;; Opening *scratch* with clipboard contents (if clipboard contains text)
(condition-case nil
    (setq initial-scratch-message (clipboard-yank))
    (error (setq initial-scratch-message nil))
)

NB : Since the *scratch* buffer will always open with the clipboard text, you might also want to change default major mode for *scratch* buffer to text 注意:由于* scratch *缓冲区将始终与剪贴板文本一起打开,因此您可能还希望将* scratch *缓冲区的默认主模式更改为文本

;; Defaulting *scratch* buffer to text-mode
(setq initial-major-mode 'text-mode)

I finally also added this to perform same clipboard paste when I open an empty .txt file 我最后还添加了此文件,以在打开一个空的.txt文件时执行相同的剪贴板粘贴操作

;; Opening empty txt files with clipboard contents (if clipboard contains text)
(add-hook 'find-file-hook 'paste-clipboard-for-empty-txt-files)
(defun paste-clipboard-for-empty-txt-files ()
  (when (and (string= (file-name-extension buffer-file-name) "txt")
                      (= (buffer-size) 0))
    (condition-case nil (clipboard-yank) (error nil))))

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

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