· 6 years ago · Oct 19, 2019, 06:22 AM
1;;; my-pastebin.el --- My interface to pastebin.el
2
3;;; Copyright (C) 2013 by C. Baxter
4
5;;; This program is free software; you can redistribute it and/or modify
6;;; it under the terms of the GNU General Public License as published by
7;;; the Free Software Foundation; either version 2, or (at your option)
8;;; any later version.
9
10;;; This program is distributed in the hope that it will be useful,
11;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13;;; GNU General Public License for more details.
14
15;;; You should have received a copy of the GNU General Public License
16;;; along with this program; see the file COPYING. If not, write to the
17;;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18;;; Boston, MA 02110-1301 USA
19
20;;; Commentary:
21;;;
22;;; This enables the pastebin api-key to be taken from a file.
23;;;
24
25;;;
26;;; Setup emacs:
27;;;
28;;; (require 'my-pastebin)
29
30;;; Code:
31
32;;; Commentout next line:
33(require 'pastebin) ;; ~/.emacs-lisp/pastebin.el
34;;;
35;;;
36;;;
37
38;;;; Copied from thesaurus.el ;;;;
39 ;
40(defun pastebin--trim-trailing-newlines (string)
41 (while (string-match "\\(.*\\)\\(\n\\|\r\\)$" string)
42 (setq string (substring string 0 -1))) ;; remove newline
43 string)
44
45;;; Without the above, you will get error message about
46;;; wrong API-key. It strips newline from file containing API-key
47
48;;;###autoload
49(defun pastebin-unique-developer-api-key-from-file (filename)
50 "A way to set the API key from the contents of a text file."
51 (interactive)
52 (setq pastebin-unique-developer-api-key
53 (and (file-exists-p filename)
54 (pastebin--trim-trailing-newlines
55 (with-temp-buffer
56 (insert-file-contents filename)
57 (buffer-substring-no-properties (point-min) (point-max)))))))
58
59
60;;;;;;;;;;;;;;;
61
62;;;
63;;; We now access our api-key from a file. We do not enter by hand.
64;;; "M-x pastebin-unique-developer-api-key-from-file RET" is redundant.
65(pastebin-unique-developer-api-key-from-file "~/.emacs-files/api-keys/pastebin.txt")
66
67;;;
68;;; We now need pastebin login and password from a secure area.
69;;;
70(let ((pastebin-personal-settings "~/.emacs-files/secure/pastebin_info.gpg"))
71 (when (file-exists-p pastebin-personal-settings)
72 (load pastebin-personal-settings)))
73
74(pastebin-login) ;; We log on to pastebin
75
76(provide 'my-pastebin)
77;;; my-pastebin.el ends here