├── .gitignore
├── Cask
├── README.org
├── copyit-pandoc.el
└── copyit.el
/.gitignore:
--------------------------------------------------------------------------------
1 | *.elc
2 | /.cask
3 |
--------------------------------------------------------------------------------
/Cask:
--------------------------------------------------------------------------------
1 | (package "copyit" "0.1.0" "Copy it, yank anything!")
2 | (source melpa)
3 |
4 | (package-file "copyit.el")
5 | (package-file "copyit-pandoc.el")
6 |
--------------------------------------------------------------------------------
/README.org:
--------------------------------------------------------------------------------
1 | * [Emacs] Copy it, yank anything!
2 |
3 | =copyit.el= is Emacs Lisp package for [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Yanking.html][Yanking]] / Clipboard [[https://www.emacswiki.org/emacs/CopyAndPaste][Copy And Paste]].
4 |
5 | ** Functions
6 | *** =copyit.el=
7 | #+BEGIN_HTML
8 |
9 |
10 | #+END_HTML
11 |
12 | | command | description |
13 | |------------------------------------+-----------------------------------------------------------------|
14 | | =M-x copyit-variable= | Copy value of symbol's variable. |
15 | | =M-x copyit-file-pathname= | Copy file pathname. |
16 | | =M-x copyit-file-content= | Copy file content. |
17 | | =M-x copyit-file-exif-information= | Copy [[https://en.wikipedia.org/wiki/Exchangeable_image_file_format][Exif]] information. (require [[http://www.imagemagick.org/script/index.php][ImageMagick]] =identify= command) |
18 | | =M-x copyit-file-as-data-uri= | Copy file content as [[https://en.wikipedia.org/wiki/Data_URI_scheme][Data URI]]. |
19 | | =M-x copyit-ssh= | Copy file content in =~/.ssh/= directory. |
20 |
21 | *** =copyit-pandoc.el=
22 | #+BEGIN_HTML
23 |
24 |
25 | #+END_HTML
26 |
27 | | command | description |
28 | |----------------------------------------+-----------------------------------|
29 | | =M-x copyit-pandoc-export-to-html= | Convert and Copy file as HTML |
30 | | =M-x copyit-pandoc-export-to-markdown= | Convert and Copy file as Markdown |
31 |
32 | =C-u M-x copyit-pandoc-export-to-html= and =C-u M-x copyit-pandoc-export-to-markdown= convert a file. When =C-u= is prepended, the content of the current buffer is converted.
33 |
34 | ** Customize
35 | *** =copyit-binary-file-copy-method= (default: =data-uri=)
36 | Binary file copy method in =copyit-file-content=.
37 | *** =copyit-ssh-directory-path= (default: ="~/.ssh/"=)
38 | Path to your SSH directory.
39 | *** =copyit-copy-bare-string= (default: =t=)
40 | Copy bare (non-quoted) string when interactively called. (="abc"= as =abc=)
41 |
--------------------------------------------------------------------------------
/copyit-pandoc.el:
--------------------------------------------------------------------------------
1 | ;;; copyit-pandoc.el --- Copy it, yank anything! -*- lexical-binding: t -*-
2 |
3 | ;; Copyright (C) 2019 USAMI Kenta
4 |
5 | ;; Author: USAMI Kenta
6 | ;; Created: 6 Jun 2016
7 | ;; Version: 0.1.0
8 | ;; Keywords: convenience yank clipboard
9 | ;; Homepage: https://github.com/zonuexe/emacs-copyit
10 | ;; Package-Requires: ((emacs "24.3") (copyit "0.1.0") (pandoc "0.0.1"))
11 |
12 | ;; This file is NOT part of GNU Emacs.
13 |
14 | ;; This program is free software; you can redistribute it and/or modify
15 | ;; it under the terms of the GNU General Public License as published by
16 | ;; the Free Software Foundation, either version 3 of the License, or
17 | ;; (at your option) any later version.
18 |
19 | ;; This program is distributed in the hope that it will be useful,
20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 | ;; GNU General Public License for more details.
23 |
24 | ;; You should have received a copy of the GNU General Public License
25 | ;; along with this program. If not, see .
26 |
27 | ;;; Commentary:
28 |
29 | ;; “Copy” is known as “Yank” in Emacs.
30 | ;;
31 | ;; ** Functions
32 | ;; - copyit-pandoc-export-to-html
33 | ;; - copyit-pandoc-export-to-markdown
34 |
35 | ;;; Code:
36 | (require 'copyit)
37 | (require 'pandoc)
38 |
39 | ;;;###autoload
40 | (defun copyit-pandoc-export-to-html (file-path)
41 | "Convert and Copy `FILE-PATH' file as HTML."
42 | (interactive "p")
43 | (kill-new
44 | (pandoc-convert-file
45 | (if (and (eq 4 file-path) buffer-file-name)
46 | buffer-file-name
47 | (read-file-name ""))
48 | nil "html")))
49 |
50 | ;;;###autoload
51 | (defun copyit-pandoc-export-to-markdown (file-path)
52 | "Convert and Copy `FILE-PATH' file as Markdown."
53 | (interactive "p")
54 | (kill-new
55 | (pandoc-convert-file
56 | (if (and (eq 4 file-path) buffer-file-name)
57 | buffer-file-name
58 | (read-file-name ""))
59 | nil (pandoc-markdown-dialect))))
60 |
61 | (provide 'copyit-pandoc)
62 | ;;; copyit-pandoc.el ends here
63 |
--------------------------------------------------------------------------------
/copyit.el:
--------------------------------------------------------------------------------
1 | ;;; copyit.el --- Copy it, yank anything! -*- lexical-binding: t -*-
2 |
3 | ;; Copyright (C) 2019 USAMI Kenta
4 |
5 | ;; Author: USAMI Kenta
6 | ;; Created: 6 Jun 2016
7 | ;; Version: 0.1.0
8 | ;; Keywords: convenience yank clipboard
9 | ;; Homepage: https://github.com/zonuexe/emacs-copyit
10 | ;; Package-Requires: ((emacs "24.3") (s "1.9.0"))
11 |
12 | ;; This file is NOT part of GNU Emacs.
13 |
14 | ;; This program is free software; you can redistribute it and/or modify
15 | ;; it under the terms of the GNU General Public License as published by
16 | ;; the Free Software Foundation, either version 3 of the License, or
17 | ;; (at your option) any later version.
18 |
19 | ;; This program is distributed in the hope that it will be useful,
20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 | ;; GNU General Public License for more details.
23 |
24 | ;; You should have received a copy of the GNU General Public License
25 | ;; along with this program. If not, see .
26 |
27 | ;;; Commentary:
28 |
29 | ;; “Copy” is known as “Yank” in Emacs.
30 | ;;
31 | ;; ** Functions
32 | ;; - copyit-variable
33 | ;; - copyit-file-pathname
34 | ;; - copyit-file-content
35 | ;; - copyit-file-exif-information
36 | ;; - copyit-file-as-data-uri
37 | ;; - copyit-ssh
38 | ;;
39 | ;; ** Customize
40 | ;; - copyit-binary-file-copy-method
41 | ;; - copyit-ssh-directory-path
42 | ;; - copyit-copy-bare-string
43 |
44 | ;;; Code:
45 |
46 | (require 'cl-lib)
47 | (require 's)
48 |
49 | (defgroup copyit nil
50 | "Copy it!"
51 | :prefix "copyit-"
52 | :group 'convenience)
53 |
54 | (defcustom copyit-binary-file-copy-method 'data-uri
55 | "Default copy method for binary file."
56 | :type '(choice (const :tag "Data URI" data-uri)
57 | (const :tag "Exif" exif)
58 | (const :tag "Base64" base64)
59 | (function-item)))
60 |
61 | (defcustom copyit-ssh-directory-path "~/.ssh/"
62 | "Directory path string for SSH."
63 | :type 'directory
64 | :group 'copyit)
65 |
66 | (defcustom copyit-copy-bare-string t
67 | "Copy non-quoted string value if T when interactively called."
68 | :type 'boolean
69 | :group 'copyit)
70 |
71 | (defun copyit--copy-binary-file (buffer)
72 | "Copy binary file content by BUFFER."
73 | (if (fboundp copyit-binary-file-copy-method)
74 | (funcall copyit-binary-file-copy-method buffer)
75 | (cl-case copyit-binary-file-copy-method
76 | ('data-uri (copyit--get-file-as-data-uri buffer))
77 | ('exif (copyit--get-file-as-exif-info buffer))
78 | ('base64 (copyit--get-file-as-base64 buffer))
79 | (:else (error "`%s' is unexpected method" copyit-binary-file-copy-method)))))
80 |
81 | (defun copyit--get-file-as-data-uri (buffer)
82 | "Get Data URI format by BUFFER."
83 | (concat "data:"
84 | (copyit--get-mime-type buffer)
85 | ";base64,"
86 | (copyit--get-file-as-base64 buffer)))
87 |
88 | (defun copyit--get-file-as-base64 (buffer)
89 | "Get Base64 encoded content by BUFFER."
90 | (with-current-buffer buffer
91 | (base64-encode-string (buffer-substring-no-properties (point-min) (point-max)))))
92 |
93 | (defun copyit--get-file-as-exif-info (file-path-or-buffer)
94 | "Get Exif informations by FILE-PATH-OR-BUFFER."
95 | (unless (executable-find "identify")
96 | (error "`identify' command not exists"))
97 | (with-temp-buffer
98 | (let ((buf (current-buffer)))
99 | (with-current-buffer (copyit--get-buffer file-path-or-buffer)
100 | (call-process-region (point-min) (point-max)
101 | "identify" nil buf nil "-verbose" "--" "-"))
102 | (buffer-substring-no-properties (point-min) (point-max)))))
103 |
104 | (defun copyit--get-buffer (file-path-or-buffer)
105 | "Return buffer by FILE-PATH-OR-BUFFER."
106 | (if (bufferp file-path-or-buffer)
107 | file-path-or-buffer
108 | (find-file-noselect file-path-or-buffer)))
109 |
110 | (defun copyit--get-mime-type (file-path-or-buffer)
111 | "Get MIME content type by FILE-PATH-OR-BUFFER."
112 | ;; require `file' command.
113 | (unless (executable-find "file")
114 | (error "`file' command not exists"))
115 | (with-temp-buffer
116 | (let ((buf (current-buffer)))
117 | (with-current-buffer (copyit--get-buffer file-path-or-buffer)
118 | (call-process-region (point-min) (point-max)
119 | "file" nil buf nil "-b" "--mime-type" "--" "-"))
120 | (goto-char (point-min))
121 | (search-forward "\n")
122 | (replace-match "")
123 | (buffer-substring-no-properties (point-min) (point-max)))))
124 |
125 | (defun copyit--pp-string (value bare-string)
126 | "Get pretty-printed string VALUE.
127 | Return non-quoted string VALUE if BARE-STRING is non-NIL."
128 | (if (and bare-string (stringp value))
129 | value
130 | (s-trim-right (pp-to-string (if (listp value) `(quote ,value) value)))))
131 |
132 | ;;;###autoload
133 | (defun copyit-variable (symbol &optional flip-bare-string)
134 | "Copy pretty-printed value SYMBOL\\='s variable.
135 | Copy quoted string if FLIP-BARE-STRING is non-NIL."
136 | (interactive
137 | (list (cl-letf (((symbol-function 'custom-variable-p) #'boundp))
138 | (read-variable "Variable: "))
139 | (not (and copyit-copy-bare-string current-prefix-arg))))
140 | (kill-new (copyit--pp-string (symbol-value symbol) flip-bare-string)))
141 |
142 | ;;;###autoload
143 | (defun copyit-file-pathname (file-path)
144 | "Copy FILE-PATH."
145 | (interactive "F")
146 | (kill-new file-path))
147 |
148 | ;;;###autoload
149 | (defun copyit-file-content (file-path)
150 | "Copy FILE-PATH content."
151 | (interactive "F")
152 | (kill-new
153 | (with-current-buffer (copyit--get-buffer file-path)
154 | (if (eq 'no-conversion buffer-file-coding-system)
155 | (copyit--copy-binary-file (current-buffer))
156 | (buffer-substring-no-properties (point-min) (point-max))))))
157 |
158 | ;;;###autoload
159 | (defun copyit-file-exif-information (file-path)
160 | "Copy exif-information by FILE-PATH."
161 | (interactive "F")
162 | (kill-new (copyit--get-file-as-exif-info file-path)))
163 |
164 | ;;;###autoload
165 | (defun copyit-file-as-data-uri (file-path)
166 | "Copy FILE-PATH content as Data URI format."
167 | (interactive "F")
168 | (kill-new (copyit--get-file-as-data-uri file-path)))
169 |
170 | ;;;###autoload
171 | (defun copyit-ssh ()
172 | "Copy ssh file."
173 | (interactive)
174 | (let ((default-directory copyit-ssh-directory-path))
175 | (call-interactively 'copyit-file-content)))
176 |
177 | (provide 'copyit)
178 | ;;; copyit.el ends here
179 |
--------------------------------------------------------------------------------