commit 82a45c90c9a4c881059a7c548987dba7ec736f83
parent f988ff2714f0a7bfc2fb0b8d220e7fae9e10fc04
Author: Vincent Demeester <vincent@sbr.pm>
Date: Sun, 19 Apr 2020 12:02:05 +0200
paste-sbr.el: static paste at sbr.pm
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Diffstat:
1 file changed, 75 insertions(+), 0 deletions(-)
diff --git a/tools/emacs/lisp/paste-sbr.el b/tools/emacs/lisp/paste-sbr.el
@@ -0,0 +1,75 @@
+;;; paste-sbr.el --- Paste to sbr.pm -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2020 Vincent Demeester
+
+;; Author: Vincent Demeester <vincent@sbr.pm>
+;; Keywords: org link github
+;;
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 3.0, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program; if not, write to the Free Software
+;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;; Commentary:
+
+;; Take selection and share it to paste.sbr.pm
+
+;;; Code:
+
+(defvar htmlize-paste-it-target-directory
+ "desktop/sites/paste.sbr.pm")
+(defvar htmlize-paste-it-base-url
+ "https://paste.sbr.pm/")
+
+(defun htmlize-paste-it ()
+ "Htmlize region-or-buffer and copy to directory."
+ (interactive)
+ (let* ((start (if (region-active-p)
+ (region-beginning) (point-min)))
+ (end (if (region-active-p)
+ (region-end) (point-max)))
+
+ (message end)
+ (message start)
+ ;; We use a basename-hash.ext.html format
+ (basename (file-name-base (buffer-name)))
+ (extension (file-name-extension (buffer-name)))
+ (hash (sha1 (current-buffer) start end))
+ (message hash)
+ (file-name (concat basename
+ "-" (substring hash 0 6)
+ "." extension
+ ".html"))
+
+ (new-file (expand-file-name (concat
+ htmlize-paste-it-target-directory
+ "/"
+ file-name) "~"))
+
+ (access-url (concat
+ htmlize-paste-it-base-url
+ file-name)))
+ ;; Region messes with clipboard, so deactivate it
+ (deactivate-mark)
+ (with-current-buffer (htmlize-region start end)
+ ;; Copy htmlized contents to target
+ (write-file new-file)
+ ;; Ensure target can be accessed by web server
+ (chmod new-file #o755))
+ ;; Put URL into clipboard
+ (kill-new access-url)))
+
+(provide 'paste-sbr)
+;;; paste-sbr.el ends here