revert to original name since the upstream is 2 years behind and i think is safe to only keep one package
This commit is contained in:
parent
fc95e28f56
commit
70ca9183de
@ -1,4 +1,4 @@
|
||||
;;; iadrian-org-auto-tangle.el --- Automatically and Asynchronously tangles org files on save -*- lexical-binding: t; -*-
|
||||
;;; org-auto-tangle.el --- Automatically and Asynchronously tangles org files on save -*- lexical-binding: t; -*-
|
||||
|
||||
;; Original Author: Yilkal Argaw <yilkalargawworkneh@gmail.com>
|
||||
;; Maintainer: Ionut Adrian Ciolan <iadrian.ciolan@gmail.com>
|
||||
@ -52,33 +52,33 @@
|
||||
(require 'org)
|
||||
(require 'ox) ; org-export--parse-option-keyword
|
||||
|
||||
(defcustom iadrian-org-auto-tangle-default nil
|
||||
"Default behavior of iadrian-org-auto-tangle.
|
||||
(defcustom org-auto-tangle-default nil
|
||||
"Default behavior of org-auto-tangle.
|
||||
|
||||
If nil (default), auto-tangle will only happen on buffers with
|
||||
the `#+auto_tangle: t' keyword. If t, auto-tangle will happen on
|
||||
all Org buffers unless `#+auto_tangle: nil' is set."
|
||||
:group 'iadrian-org-auto-tangle
|
||||
:group 'org-auto-tangle
|
||||
:type 'boolean)
|
||||
|
||||
(defcustom iadrian-org-auto-tangle-babel-safelist '()
|
||||
(defcustom org-auto-tangle-babel-safelist '()
|
||||
"List of full path of files for which code blocks need to be evaluated.
|
||||
|
||||
By default, code blocks are not evaluated during the auto-tangle to avoid
|
||||
possible code execution from unstrusted source. To enable code blocks evaluation
|
||||
for a specific file, add its full path to this list."
|
||||
:group 'iadrian-org-auto-tangle
|
||||
:group 'org-auto-tangle
|
||||
:type '(repeat (file :tag "Full file path")))
|
||||
|
||||
(defun iadrian-org-auto-tangle-find-value (buffer)
|
||||
(defun org-auto-tangle-find-value (buffer)
|
||||
"Return the value of the `auto_tangle' keyword in BUFFER."
|
||||
(with-current-buffer buffer
|
||||
(cdr (assoc "AUTO_TANGLE" (org-collect-keywords '("AUTO_TANGLE"))))))
|
||||
|
||||
;; This is modeled after `org-export-filters-alist', since it is
|
||||
;; passed to `org-export--parse-option-keyword'.
|
||||
(defconst iadrian-org-auto-tangle-options-alist
|
||||
'((:with-vars nil "vars" iadrian-org-auto-tangle-with-vars))
|
||||
(defconst org-auto-tangle-options-alist
|
||||
'((:with-vars nil "vars" org-auto-tangle-with-vars))
|
||||
"Alist between auto-tangle properties and ways to set them.
|
||||
|
||||
The key of the alist is the property name, and the value is a list
|
||||
@ -107,12 +107,12 @@ BEHAVIOR determines how Org should handle multiple keywords for
|
||||
Values set through KEYWORD and OPTION have precedence over
|
||||
DEFAULT.")
|
||||
|
||||
(defgroup iadrian-org-auto-tangle nil
|
||||
(defgroup org-auto-tangle nil
|
||||
"Automatic tangling of `org-mode' documents."
|
||||
:tag "Org Auto Tangle"
|
||||
:group 'org-babel)
|
||||
|
||||
(defcustom iadrian-org-auto-tangle-with-vars nil
|
||||
(defcustom org-auto-tangle-with-vars nil
|
||||
"Non-nil means pass VARS variables to the async tangling process.
|
||||
|
||||
This option can also be set with the AUTO_TANGLE keyword,
|
||||
@ -121,10 +121,10 @@ e.g. \"vars:calendar-latitude\".
|
||||
The `org-src-preserve-indentation', `org-babel-pre-tangle-hook',
|
||||
and `org-babel-post-tangle-hook' variables are automatically
|
||||
preserved and do not need to be listed here."
|
||||
:group 'iadrian-org-auto-tangle
|
||||
:group 'org-auto-tangle
|
||||
:type '(repeat (symbol :tag "Variable name")))
|
||||
|
||||
(defun iadrian-org-auto-tangle--get-inbuffer-options ()
|
||||
(defun org-auto-tangle--get-inbuffer-options ()
|
||||
"Return current buffer auto-tangle options, as a plist.
|
||||
|
||||
Assume buffer is in Org mode. Narrowing, if any, is ignored."
|
||||
@ -138,38 +138,38 @@ Assume buffer is in Org mode. Narrowing, if any, is ignored."
|
||||
plist
|
||||
(mapcar (lambda (v)
|
||||
(let ((org-export-options-alist)))
|
||||
(iadrian-org-auto-tangle--parse-auto-tangle-keyword v))
|
||||
(org-auto-tangle--parse-auto-tangle-keyword v))
|
||||
values))))))))
|
||||
|
||||
(defun iadrian-org-auto-tangle--parse-auto-tangle-keyword (auto-tangle)
|
||||
(defun org-auto-tangle--parse-auto-tangle-keyword (auto-tangle)
|
||||
"Parse an AUTO-TANGLE line and return values as a plist."
|
||||
(let ((org-export-options-alist iadrian-org-auto-tangle-options-alist))
|
||||
(let ((org-export-options-alist org-auto-tangle-options-alist))
|
||||
(org-export--parse-option-keyword auto-tangle)))
|
||||
|
||||
;; Fix async tangling failing over TRAMP
|
||||
(defun iadrian-org-auto-tangle-async (file)
|
||||
(defun org-auto-tangle-async (file)
|
||||
"iAdrian_PATCH: Tangle FILE asynchronously unless it's a TRAMP path (then fallback to sync)."
|
||||
(if (file-remote-p file)
|
||||
;; Use current buffer over TRAMP. Slower but safe
|
||||
(with-current-buffer (get-file-buffer file)
|
||||
(org-babel-tangle))
|
||||
;; Normal async tangle locally
|
||||
(message "[iadrian-org-auto-tangle] Tangling %s asynchronously..." (buffer-file-name))
|
||||
(message "[org-auto-tangle] Tangling %s asynchronously..." (buffer-file-name))
|
||||
(async-start
|
||||
(let* ((buf-vars (plist-get (iadrian-org-auto-tangle--get-inbuffer-options)
|
||||
(let* ((buf-vars (plist-get (org-auto-tangle--get-inbuffer-options)
|
||||
:with-vars))
|
||||
(with-vars (if buf-vars
|
||||
(mapcar #'intern
|
||||
(org-uniquify (org-split-string
|
||||
(symbol-name buf-vars) ":")))
|
||||
iadrian-org-auto-tangle-with-vars))
|
||||
org-auto-tangle-with-vars))
|
||||
(preserved (mapcar (lambda (v)
|
||||
(cons v (symbol-value v)))
|
||||
(append '(org-src-preserve-indentation
|
||||
org-babel-pre-tangle-hook
|
||||
org-babel-post-tangle-hook)
|
||||
with-vars)))
|
||||
(evaluate (not (member file iadrian-org-auto-tangle-babel-safelist))))
|
||||
(evaluate (not (member file org-auto-tangle-babel-safelist))))
|
||||
`(lambda ()
|
||||
(require 'org)
|
||||
(let ((start-time (current-time))
|
||||
@ -182,30 +182,30 @@ Assume buffer is in Org mode. Narrowing, if any, is ignored."
|
||||
(lambda (tangle-time)
|
||||
(message "%s %s seconds" message-string tangle-time))))))
|
||||
|
||||
(defun iadrian-org-auto-tangle-tangle-if-needed ()
|
||||
"Call iadrian-org-auto-tangle-async if needed.
|
||||
(defun org-auto-tangle-tangle-if-needed ()
|
||||
"Call org-auto-tangle-async if needed.
|
||||
|
||||
Tangle will happen depending on the value of
|
||||
`iadrian-org-auto-tangle-default' and on the presence and value of the
|
||||
`org-auto-tangle-default' and on the presence and value of the
|
||||
`#+auto_tangle' keyword in the current buffer. If present,
|
||||
`#+auto_tangle' always overrides `iadrian-org-auto-tangle-default'."
|
||||
(let ((auto-tangle-kw (iadrian-org-auto-tangle-find-value (current-buffer))))
|
||||
`#+auto_tangle' always overrides `org-auto-tangle-default'."
|
||||
(let ((auto-tangle-kw (org-auto-tangle-find-value (current-buffer))))
|
||||
(when (and (derived-mode-p 'org-mode)
|
||||
(if auto-tangle-kw
|
||||
(not (member "nil" auto-tangle-kw))
|
||||
iadrian-org-auto-tangle-default))
|
||||
(iadrian-org-auto-tangle-async (buffer-file-name)))))
|
||||
org-auto-tangle-default))
|
||||
(org-auto-tangle-async (buffer-file-name)))))
|
||||
|
||||
;;;###autoload
|
||||
(define-minor-mode iadrian-org-auto-tangle-mode
|
||||
(define-minor-mode org-auto-tangle-mode
|
||||
"Automatically tangle org-mode files with the option #+auto_tangle: t."
|
||||
:lighter " org-a-t"
|
||||
|
||||
(if iadrian-org-auto-tangle-mode
|
||||
(add-hook 'after-save-hook #'iadrian-org-auto-tangle-tangle-if-needed
|
||||
(if org-auto-tangle-mode
|
||||
(add-hook 'after-save-hook #'org-auto-tangle-tangle-if-needed
|
||||
nil 'local)
|
||||
(remove-hook 'after-save-hook #'iadrian-org-auto-tangle-tangle-if-needed 'local)))
|
||||
(remove-hook 'after-save-hook #'org-auto-tangle-tangle-if-needed 'local)))
|
||||
|
||||
(provide 'iadrian-org-auto-tangle)
|
||||
(provide 'org-auto-tangle)
|
||||
|
||||
;;; iadrian-org-auto-tangle.el ends here
|
||||
;;; org-auto-tangle.el ends here
|
||||
Loading…
Reference in New Issue
user.block.title