fixed autotangle over tramp. The hacky barbarian way
This commit is contained in:
parent
42adda3899
commit
aa8109cd5f
@ -1,14 +1,37 @@
|
|||||||
;;; iadrian-iadrian-org-auto-tangle.el --- Automatically and Asynchronously tangles org files on save -*- lexical-binding: t; -*-
|
;;; iadrian-iadrian-org-auto-tangle.el --- Automatically and Asynchronously tangles org files on save -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;; Original Author: Yilkal Argaw <yilkalargawworkneh@gmail.com>
|
;; Original Author: Yilkal Argaw <yilkalargawworkneh@gmail.com>
|
||||||
;; Original License: https://github.com/yilkalargaw/org-auto-tangle/blob/master/License.org
|
|
||||||
;; Maintainer: Ionut Adrian Ciolan <iadrian.ciolan@gmail.com>
|
;; Maintainer: Ionut Adrian Ciolan <iadrian.ciolan@gmail.com>
|
||||||
|
;; URL: https://github.com/yilkalargaw/iadrian-org-auto-tangle
|
||||||
;; Version: 0.6.1
|
;; Version: 0.6.1
|
||||||
;; Keywords: outlines
|
;; Keywords: outlines
|
||||||
;; Package-Requires: ((emacs "24.1") (async "1.9.3"))
|
;; Package-Requires: ((emacs "24.1") (async "1.9.3"))
|
||||||
|
|
||||||
;; This file is not part of GNU Emacs
|
;; This file is not part of GNU Emacs
|
||||||
|
|
||||||
|
;; Copyright (c) 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:
|
;;; Commentary:
|
||||||
|
|
||||||
;; It is common to want to tangle org files everytime you save your changes,
|
;; It is common to want to tangle org files everytime you save your changes,
|
||||||
@ -21,6 +44,9 @@
|
|||||||
;; - Add #+auto_tangle: t to your tangled org file
|
;; - Add #+auto_tangle: t to your tangled org file
|
||||||
;; - Make changes to the emacs file and save your changes
|
;; - Make changes to the emacs file and save your changes
|
||||||
|
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
(require 'async)
|
(require 'async)
|
||||||
(require 'cl-lib)
|
(require 'cl-lib)
|
||||||
(require 'org)
|
(require 'org)
|
||||||
@ -120,35 +146,73 @@ Assume buffer is in Org mode. Narrowing, if any, is ignored."
|
|||||||
(let ((org-export-options-alist iadrian-org-auto-tangle-options-alist))
|
(let ((org-export-options-alist iadrian-org-auto-tangle-options-alist))
|
||||||
(org-export--parse-option-keyword auto-tangle)))
|
(org-export--parse-option-keyword auto-tangle)))
|
||||||
|
|
||||||
|
;; Fix async tangling failing over TRAMP
|
||||||
(defun iadrian-org-auto-tangle-async (file)
|
(defun iadrian-org-auto-tangle-async (file)
|
||||||
"Invoke `org-babel-tangle-file' asynchronously on FILE."
|
"Tangle FILE asynchronously unless it's a TRAMP path (then fallback to sync)."
|
||||||
(message "Tangling %s..." (buffer-file-name))
|
(if (file-remote-p file)
|
||||||
(async-start
|
;; Use current buffer over TRAMP. Slower but safe
|
||||||
(let* ((buf-vars (plist-get (iadrian-org-auto-tangle--get-inbuffer-options)
|
(with-current-buffer (get-file-buffer file)
|
||||||
:with-vars))
|
(org-babel-tangle))
|
||||||
(with-vars (if buf-vars
|
;; Normal async tangle locally
|
||||||
(mapcar #'intern
|
(message "[iadrian-org-auto-tangle] Tangling %s asynchronously..." (buffer-file-name))
|
||||||
(org-uniquify (org-split-string
|
(async-start
|
||||||
(symbol-name buf-vars) ":")))
|
(let* ((buf-vars (plist-get (iadrian-org-auto-tangle--get-inbuffer-options)
|
||||||
iadrian-org-auto-tangle-with-vars))
|
:with-vars))
|
||||||
(preserved (mapcar (lambda (v)
|
(with-vars (if buf-vars
|
||||||
(cons v (symbol-value v)))
|
(mapcar #'intern
|
||||||
(append '(org-src-preserve-indentation
|
(org-uniquify (org-split-string
|
||||||
org-babel-pre-tangle-hook
|
(symbol-name buf-vars) ":")))
|
||||||
org-babel-post-tangle-hook)
|
iadrian-org-auto-tangle-with-vars))
|
||||||
with-vars)))
|
(preserved (mapcar (lambda (v)
|
||||||
(evaluate (not (member file iadrian-org-auto-tangle-babel-safelist))))
|
(cons v (symbol-value v)))
|
||||||
(lambda ()
|
(append '(org-src-preserve-indentation
|
||||||
(require 'org)
|
org-babel-pre-tangle-hook
|
||||||
(let ((start-time (current-time))
|
org-babel-post-tangle-hook)
|
||||||
(non-essential t)
|
with-vars)))
|
||||||
(org-confirm-babel-evaluate evaluate))
|
(evaluate (not (member file iadrian-org-auto-tangle-babel-safelist))))
|
||||||
(cl-progv (mapcar #'car preserved) (mapcar #'cdr preserved)
|
`(lambda ()
|
||||||
(org-babel-tangle-file file))
|
(require 'org)
|
||||||
(format "%.2f" (float-time (time-since start-time))))))
|
(let ((start-time (current-time))
|
||||||
(let ((message-string (format "Tangling %S completed after" file)))
|
(non-essential t)
|
||||||
(lambda (tangle-time)
|
(org-confirm-babel-evaluate ,evaluate))
|
||||||
(message "%s %s seconds" message-string tangle-time)))))
|
(cl-progv ',(mapcar #'car preserved) ',(mapcar #'cdr preserved)
|
||||||
|
(org-babel-tangle-file ,file))
|
||||||
|
(format "%.2f" (float-time (time-since start-time))))))
|
||||||
|
(let ((message-string (format "Tangling %S completed after" file)))
|
||||||
|
(lambda (tangle-time)
|
||||||
|
(message "%s %s seconds" message-string tangle-time))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;(defun iadrian-org-auto-tangle-async (file)
|
||||||
|
; "Invoke `org-babel-tangle-file' asynchronously on FILE."
|
||||||
|
; (message "Tangling %s..." (buffer-file-name))
|
||||||
|
; (async-start
|
||||||
|
; (let* ((buf-vars (plist-get (iadrian-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))
|
||||||
|
; (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))))
|
||||||
|
; (lambda ()
|
||||||
|
; (require 'org)
|
||||||
|
; (let ((start-time (current-time))
|
||||||
|
; (non-essential t)
|
||||||
|
; (org-confirm-babel-evaluate evaluate))
|
||||||
|
; (cl-progv (mapcar #'car preserved) (mapcar #'cdr preserved)
|
||||||
|
; (org-babel-tangle-file file))
|
||||||
|
; (format "%.2f" (float-time (time-since start-time))))))
|
||||||
|
; (let ((message-string (format "Tangling %S completed after" file)))
|
||||||
|
; (lambda (tangle-time)
|
||||||
|
; (message "%s %s seconds" message-string tangle-time)))))
|
||||||
|
|
||||||
(defun iadrian-org-auto-tangle-tangle-if-needed ()
|
(defun iadrian-org-auto-tangle-tangle-if-needed ()
|
||||||
"Call iadrian-org-auto-tangle-async if needed.
|
"Call iadrian-org-auto-tangle-async if needed.
|
||||||
Loading…
Reference in New Issue
user.block.title