Browse code
feat(emacs): add pastebin package
Showing 2 changed files
... | ... |
@@ -140,6 +140,13 @@ |
140 | 140 |
|
141 | 141 |
(fwoar/setup-load-path) |
142 | 142 |
|
143 |
+(use-package fwoar-pastebin :ensure nil |
|
144 |
+ :custom |
|
145 |
+ (fwoar-pastebin-tramp-url (when (file-exists-p "~/.pastebin-name") |
|
146 |
+ (car (read-sexps-in-file "~/.pastebin-name")))) |
|
147 |
+ (fwoar-pastebin-web-url-pattern (when (file-exists-p "~/.pastebin-name") |
|
148 |
+ (cadr (read-sexps-in-file "~/.pastebin-name"))))) |
|
149 |
+ |
|
143 | 150 |
(defun fwoar/package-configuration (package) |
144 | 151 |
(fwoar/setup-load-path) |
145 | 152 |
(let* ((local-configs) |
... | ... |
@@ -524,15 +531,6 @@ |
524 | 531 |
|
525 | 532 |
(defvar url-pattern (when (file-exists-p "~/.pastebin-name") |
526 | 533 |
(car (read-sexps-in-file "~/.pastebin-name")))) |
527 |
-(defun pastebin-buffer () |
|
528 |
- (interactive) |
|
529 |
- (let* ((extension (file-name-extension (elt (split-string (buffer-name) "<") 0))) |
|
530 |
- (htmlized-buffer (htmlize-buffer))) |
|
531 |
- (with-current-buffer htmlized-buffer |
|
532 |
- (let ((result-name-hash (sha1 (current-buffer)))) |
|
533 |
- (write-file (format url-pattern result-name-hash extension)) |
|
534 |
- (message "Wrote file to: %s.%s.html" result-name-hash extension) |
|
535 |
- (browse-url (format "https://fwoar.co/pastebin/%s.%s.html" result-name-hash extension)))))) |
|
536 | 534 |
|
537 | 535 |
(defun delete-mru-window () |
538 | 536 |
(interactive) |
539 | 537 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,63 @@ |
1 |
+;;; fwoar-pastebin.el --- Save htmlized version of buffer to a server -*- lexical-binding: t; tab-width: 8; -*- |
|
2 |
+ |
|
3 |
+;; Copyright (C) 2017 Edward Langley |
|
4 |
+ |
|
5 |
+;; Author: Edward Langley <fwoar@elangley.org> |
|
6 |
+;; Keywords: lisp |
|
7 |
+;; Version: 0.0.1 |
|
8 |
+ |
|
9 |
+;; This program is free software; you can redistribute it and/or modify |
|
10 |
+;; it under the terms of the GNU General Public License as published by |
|
11 |
+;; the Free Software Foundation, either version 2 of the License, or |
|
12 |
+;; (at your option) any later version. |
|
13 |
+ |
|
14 |
+;; This program is distributed in the hope that it will be useful, |
|
15 |
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
+;; GNU General Public License for more details. |
|
18 |
+ |
|
19 |
+;; You should have received a copy of the GNU General Public License |
|
20 |
+;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21 |
+ |
|
22 |
+;;; Commentary: |
|
23 |
+ |
|
24 |
+;; Put a description of the package here |
|
25 |
+ |
|
26 |
+;;; Code: |
|
27 |
+ |
|
28 |
+;; code goes here |
|
29 |
+ |
|
30 |
+(defgroup fwoar-pastebin nil |
|
31 |
+ "Configuration for simple pastebin" |
|
32 |
+ :prefix "fwoar-pastebin-" |
|
33 |
+ :group 'application) |
|
34 |
+ |
|
35 |
+(defcustom fwoar-pastebin-tramp-url nil |
|
36 |
+ "A tramp-writable url to the pastebin" |
|
37 |
+ :group 'fwoar-pastebin |
|
38 |
+ :type 'string) |
|
39 |
+ |
|
40 |
+(defcustom fwoar-pastebin-web-url-pattern nil |
|
41 |
+ "An appropriate URL for viewing the uploaded files" |
|
42 |
+ :group 'fwoar-pastebin |
|
43 |
+ :type 'string) |
|
44 |
+ |
|
45 |
+;;;###autoload |
|
46 |
+(defun pastebin-buffer () |
|
47 |
+ (interactive) |
|
48 |
+ (let* ((extension (file-name-extension (elt (split-string (buffer-name) |
|
49 |
+ "<") |
|
50 |
+ 0))) |
|
51 |
+ (htmlized-buffer (htmlize-buffer))) |
|
52 |
+ (with-current-buffer htmlized-buffer |
|
53 |
+ (let ((result-name-hash (sha1 (current-buffer)))) |
|
54 |
+ (write-file (format fwoar-pastebin-tramp-url |
|
55 |
+ result-name-hash |
|
56 |
+ extension)) |
|
57 |
+ (message "Wrote file to: %s.%s.html" result-name-hash extension) |
|
58 |
+ (browse-url (format fwoar-pastebin-web-url-pattern |
|
59 |
+ result-name-hash |
|
60 |
+ extension)))))) |
|
61 |
+ |
|
62 |
+(provide 'fwoar-pastebin) |
|
63 |
+;;; fwoar-pastebin.el ends here |