emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/engrave-faces 2fee4f7 24/36: Create engrave-faces-BACKE


From: ELPA Syncer
Subject: [elpa] externals/engrave-faces 2fee4f7 24/36: Create engrave-faces-BACKEND-file command
Date: Tue, 31 Aug 2021 01:57:28 -0400 (EDT)

branch: externals/engrave-faces
commit 2fee4f736a18f00dd97732f3f5b43d54d1bbe7ac
Author: TEC <tec@tecosaur.com>
Commit: TEC <tec@tecosaur.com>

    Create engrave-faces-BACKEND-file command
---
 engrave-faces.el | 88 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 59 insertions(+), 29 deletions(-)

diff --git a/engrave-faces.el b/engrave-faces.el
index 6bf9640..e173ffb 100644
--- a/engrave-faces.el
+++ b/engrave-faces.el
@@ -38,35 +38,6 @@
 
 (require 'map)
 
-;;;###autoload
-(defvar engrave-faces--backends nil)
-
-;;;###autoload
-(defmacro engrave-faces-define-backend (name extension face-transformer 
&optional standalone-transformer view-setup)
-  `(progn (add-to-list 'engrave-faces--backends
-                       (list ,name :face-transformer ,face-transformer 
:extension ,extension))
-          (defun ,(intern (concat "engrave-faces-" name "-buffer")) (&optional 
switch-to-result)
-            ,(concat "Convert buffer to " name " formatting.")
-            (interactive '(t))
-            (let ((buf (engrave-faces-buffer ,name)))
-              (when switch-to-result
-                (switch-to-buffer buf)
-                ,(when view-setup `(funcall ,view-setup)))
-              buf))
-          ,(when standalone-transformer
-             `(defun ,(intern (concat "engrave-faces-" name 
"-buffer-standalone")) (&optional switch-to-result)
-                (interactive '(t))
-                ,(concat "Export the current buffer to a standalone " name " 
buffer.")
-                (let ((buf (engrave-faces-buffer ,name)))
-                  (with-current-buffer buf
-                    (funcall ,standalone-transformer))
-                  (when switch-to-result
-                    (switch-to-buffer buf)
-                    ,(when view-setup `(funcall ,view-setup)))
-                  buf)))
-          (defvar ,(intern (concat "engrave-faces-" name "-before-hook")) nil)
-          (defvar ,(intern (concat "engrave-faces-" name "-after-hook")) nil)))
-
 (defgroup engrave-faces nil
   "Export buffers with font-lock information to other formats."
   :group 'hypermedia)
@@ -90,6 +61,65 @@ buffer.  You may use them to modify the outlook of the final 
output."
   :type 'hook
   :group 'engrave-faces)
 
+;;;###autoload
+(defvar engrave-faces--backends nil)
+
+;;;###autoload
+(defmacro engrave-faces-define-backend (backend extension face-transformer 
&optional standalone-transformer view-setup)
+  "Create a new engraving backend BACKEND.
+EXTENSION is the extension which will be used when writing engraved files.
+FACE-TRANSFORMER is the all important function which can be called with a
+list of faces and some content to apply those faces to and generate an output
+string accordingly.
+Should a pre/postable make sense for complete files using BACKEND, a
+STANDALONE-TRANSFORMER may be defined which operates on a buffer which has been
+generated by `engrave-faces-buffer' and is called after hooks.
+If STANDALONE-TRANSFORMER is given it will be used when directly creating a 
file,
+and cause a -standalone version of the buffer transforming function to be 
created."
+  `(progn (add-to-list 'engrave-faces--backends
+                       (list ,backend :face-transformer ,face-transformer 
:extension ,extension))
+          (defun ,(intern (concat "engrave-faces-" backend "-buffer")) 
(&optional switch-to-result)
+            ,(concat "Convert buffer to " backend " formatting.")
+            (interactive '(t))
+            (let ((buf (engrave-faces-buffer ,backend)))
+              (when switch-to-result
+                (switch-to-buffer buf)
+                ,(when view-setup `(funcall ,view-setup)))
+              buf))
+          ,(when standalone-transformer
+             `(defun ,(intern (concat "engrave-faces-" backend 
"-buffer-standalone")) (&optional switch-to-result)
+                (interactive '(t))
+                ,(concat "Export the current buffer to a standalone " backend 
" buffer.")
+                (let ((buf (engrave-faces-buffer ,backend)))
+                  (with-current-buffer buf
+                    (funcall ,standalone-transformer))
+                  (when switch-to-result
+                    (switch-to-buffer buf)
+                    ,(when view-setup `(funcall ,view-setup)))
+                  buf)))
+          (defun ,(intern (concat "engrave-faces-" backend "-file")) (file 
&optional open-result)
+            ,(concat "Convert file to " backend " formatting.")
+            (interactive (list buffer-file-name t))
+            (let ((output-file (engrave-faces-file file ,extension ,backend 
,standalone-transformer)))
+              (when open-result (find-file output-file))
+              output-file))
+          (defvar ,(intern (concat "engrave-faces-" backend "-before-hook")) 
nil)
+          (defvar ,(intern (concat "engrave-faces-" backend "-after-hook")) 
nil)))
+
+(defun engrave-faces-file (file extension backend &optional postprocessor)
+  "Using BACKEND, engrave FILE and save it as FILE.EXTENSION.
+If a POSTPROCESSOR function is provided, it is called before saving."
+  (let ((output-file (concat file extension)))
+    (with-temp-buffer
+      (insert-file-contents file)
+      (let ((buffer-file-name file))
+        (normal-mode)
+        (with-current-buffer (engrave-faces-buffer backend)
+          (when postprocessor (funcall postprocessor))
+          (write-region (point-min) (point-max) output-file)
+          (kill-buffer))))
+    output-file))
+
 (defun engrave-faces-buffer (backend)
   "Export the current buffer with BACKEND and return the created buffer."
   (save-excursion



reply via email to

[Prev in Thread] Current Thread [Next in Thread]