LoginSignup
5
5

More than 5 years have passed since last update.

開いているファイル/フォルダのパスをクリップボードに保存する

Posted at

ちょっとした手間を省くElispです。

この設定ではM-x put-current-path-to-clipboardもしくはC-c C-c pで現在のバッファのパスをクリップボードに読み込みます。

;;; Get current path and put it to clipboard
(defun put-current-path-to-clipboard ()
  (interactive)
  (let ((file-path buffer-file-name)
        (dir-path default-directory))
    (cond (file-path
           (kill-new (expand-file-name file-path))
           (message "This file path is on the clipboard!"))
          (dir-path
           (kill-new (expand-file-name dir-path))
           (message "This directory path is on the clipboard!"))
          (t
           (error-message-string "Fail to get path name.")
           ))))
(global-set-key (kbd "C-c C-c p") 'put-current-path-to-clipboard)
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5