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

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

[nongnu] elpa/org-auto-tangle 109e39f3df 02/56: coded an initial version


From: ELPA Syncer
Subject: [nongnu] elpa/org-auto-tangle 109e39f3df 02/56: coded an initial version of org-auto-tangle
Date: Mon, 6 Jun 2022 11:58:50 -0400 (EDT)

branch: elpa/org-auto-tangle
commit 109e39f3df2b2f864c5ab8346178d2955993553c
Author: lispy-dobby <yilkalargawworkneh@gmail.com>
Commit: lispy-dobby <yilkalargawworkneh@gmail.com>

    coded an initial version of org-auto-tangle
---
 org-auto-tangle.el | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)

diff --git a/org-auto-tangle.el b/org-auto-tangle.el
new file mode 100644
index 0000000000..544bafafe9
--- /dev/null
+++ b/org-auto-tangle.el
@@ -0,0 +1,97 @@
+;;; org-auto-tangle --- Basically it automatically tangles an org file based 
on an org option
+
+;; Author: Yilkal Argaw
+;; URL: https://github.com/yilkalargaw/auto-tangle
+;; Version: 0.0.1
+
+;; This file is not part of GNU Emacs
+
+;; Copyright <2021> <Yilkal Argaw>
+;;
+;; Redistribution and use in source and binary forms, with or without
+;; modification, are permitted provided that the following conditions are
+;; met:
+;;
+;;
+;; 1. Redistributions of source code must retain the above copyright
+;; notice, this list of conditions and the following disclaimer.
+;;
+;;
+;; 2. Redistributions in binary form must reproduce the above copyright
+;; notice, this list of conditions and the following disclaimer in the
+;; documentation and/or other materials provided with the distribution.
+
+;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+;; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+;; USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+;; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+;; OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+;; SUCH DAMAGE.
+
+
+;;; Commentary:
+;; It is common to want to tangle org files everytime you save your changes,
+;; especially for common tangled init files. So this program allows you to
+;; do so using #+auto_tangle option in an org file. It also does so 
asynchronously
+;; so it does let you emacs session hang
+
+;;; Usage:
+
+;; - Add #+auto_tangle:t to your tangled org file
+;; - Make changes to the emacs file and save your changes
+
+
+;;; Code:
+
+(require 'async)
+
+
+(defcustom org-auto-tangle-tangle-on-save t
+  "Enables the parsing of auto-tanlge option for org files."
+  :type 'boolean
+  :group 'auto-tangle)
+
+(add-hook 'org-mode-hook
+          (lambda ()
+           (when auto-tangle-tangle-on-save
+             (defun org-auto-tangle-find-value (buffer)
+               "Search the `auto_tangle' property in BUFFER and extracts it 
when found."
+               (with-current-buffer buffer
+                  (save-restriction
+                    (widen)
+                    (save-excursion
+                     (goto-char (point-min))
+                     (when (re-search-forward "^#\\+auto_tangle: \\(.*\\)" nil 
:noerror)
+                       (match-string 1))))))
+
+
+             (defun org-auto-tangle-async (file)
+               "Invoke `org-babel-tangle-file' asynchronously."
+               (message "Tangling %s..." (buffer-file-name))
+               (async-start
+                (let ((args (list file)))
+                   `(lambda ()
+                     (require 'org)
+                     (let ((start-time (current-time)))
+                       (apply #'org-babel-tangle-file ',args)
+                       (format "%.2f" (float-time (time-since start-time))))))
+                (let ((message-string (format "Tangling %S completed after " 
file)))
+                   `(lambda (tangle-time)
+                     (message (concat ,message-string
+                                      (format "%s seconds" tangle-time)))))))
+
+             (add-hook 'after-save-hook
+                       (lambda () (when (and (org-auto-tangle-find-value 
(current-buffer))
+                                             (not (string= 
(org-auto-tangle-find-value(current-buffer)) "nil")))
+                                     (org-auto-tangle-async 
(buffer-file-name))))
+                       nil 'local))))
+
+(provide 'org-auto-tangle)
+
+;;; org-auto-tangle.el ends here



reply via email to

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