[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/org-auto-tangle 5ffbe41243 39/56: Add org-auto-tangle-defa
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/org-auto-tangle 5ffbe41243 39/56: Add org-auto-tangle-default variable |
Date: |
Mon, 6 Jun 2022 11:58:54 -0400 (EDT) |
branch: elpa/org-auto-tangle
commit 5ffbe4124339fe562dc91968c65d56a88222be18
Author: Diego Zamboni <diego@zzamboni.org>
Commit: Diego Zamboni <diego@zzamboni.org>
Add org-auto-tangle-default variable
- Introduce a new variable org-auto-tangle-default which determines the
default behavior. With its default value of nil, the behavior remains
unchanged, with auto-tangling enabled for files with the
#+auto_tangle: t option. If set to t, the default is to auto-tangle
all org files, and it can be disabled by setting #+auto_tangle: nil.
If present, the value of #+auto_tangle always overrides the default.
- Simplified org-auto-tangle-find-value by using the built-in function
org-collect-keywords.
---
README.org | 6 ++++--
org-auto-tangle.el | 42 +++++++++++++++++++++++++-----------------
2 files changed, 29 insertions(+), 19 deletions(-)
diff --git a/README.org b/README.org
index 50fd76c0c3..2e1a85f67f 100644
--- a/README.org
+++ b/README.org
@@ -24,18 +24,20 @@ Simply require the package in you emacs init and hook it
into org-mode.
or you can use use-package
#+begin_src emacs-lisp
-
(use-package org-auto-tangle
:load-path "site-lisp/org-auto-tangle/" ;; this line is necessary only if
you cloned the repo in your site-lisp directory
:defer t
:hook (org-mode . org-auto-tangle-mode))
-
#+end_src
If the minor mode is on, it will try to automatically tangle
your org files if they contain a non nil value for the
~#+auto_tangle:~ option.
+You can configure auto-tangle as the default behavior for all org buffers by
+setting the ~org-auto-tangle-default~ variable to ~t~. In this case, you can
disable
+it for some buffers by setting the ~#+auto_tangle:~ option to ~nil~.
+
* License
The org-auto-tangle is licensed under the The 2-Clause BSD License.
diff --git a/org-auto-tangle.el b/org-auto-tangle.el
index 03bb0190db..c15bad7b9c 100644
--- a/org-auto-tangle.el
+++ b/org-auto-tangle.el
@@ -48,16 +48,16 @@
(require 'async)
+(defvar org-auto-tangle-default nil
+ "Default behavior of org-auto-tangle.
-(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:[ \t]+\\([^ \f\t\n\r\v]+\\)[
\t]*" nil :noerror)
- (match-string 1))))))
+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.")
+
+(defun org-auto-tangle-find-value ()
+ "Search the `auto_tangle' property in the current buffer and extracts it
when found."
+ (cadar (org-collect-keywords '("auto_tangle"))))
(defun org-auto-tangle-async (file)
"Invoke `org-babel-tangle-file' asynchronously on FILE."
@@ -73,21 +73,29 @@
`(lambda (tangle-time)
(message "%s %s seconds",message-string tangle-time)))))
-(defun org-auto-tangle-tangle-if-tag-exists ()
- "Check if the #+auto_tangle option exists and call org-auto-tangle-async if
it exists."
- (when (and (eq major-mode 'org-mode)
- (org-auto-tangle-find-value (current-buffer))
- (not (string= (org-auto-tangle-find-value(current-buffer)) "nil")))
- (org-auto-tangle-async (buffer-file-name))))
+(defun org-auto-tangle-tangle-if-needed ()
+ "Call org-auto-tangle-async if needed.
+
+Tangle will happen depending on the value of
+`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 `org-auto-tangle-default'."
+ (let ((auto-tangle-kw (org-auto-tangle-find-value)))
+ (when (and (eq major-mode 'org-mode)
+ (or (and auto-tangle-kw
+ (not (string= auto-tangle-kw "nil")))
+ (and (not auto-tangle-kw)
+ org-auto-tangle-default)))
+ (org-auto-tangle-async (buffer-file-name)))))
(define-minor-mode org-auto-tangle-mode
"Automatically tangle org-mode files with the option #+auto_tangle: t."
:lighter " org-a-t"
(if org-auto-tangle-mode
- (add-hook 'after-save-hook #'org-auto-tangle-tangle-if-tag-exists
+ (add-hook 'after-save-hook #'org-auto-tangle-tangle-if-needed
nil 'local)
- (remove-hook 'after-save-hook #'org-auto-tangle-tangle-if-tag-exists
'local)))
+ (remove-hook 'after-save-hook #'org-auto-tangle-tangle-if-needed 'local)))
(provide 'org-auto-tangle)
- [nongnu] elpa/org-auto-tangle 7bd6e9c934 38/56: improve the regex used to parse for the #+auto_tangle: option, (continued)
- [nongnu] elpa/org-auto-tangle 7bd6e9c934 38/56: improve the regex used to parse for the #+auto_tangle: option, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle fca066b145 07/56: remove the introduction header, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle d9eedc3ec0 22/56: corrected the license to match bsd-2-clause according to licencsee gem, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle bebfd65316 15/56: Formatted the license file to standard format, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle 7896c0efe0 11/56: Merge pull request #1 from syohex/dependencies, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle 0add68b91c 17/56: corrected the doc string issue raised by checkdoc, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle b23eafd743 05/56: corrected the variable name in conditialal when, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle 0e67925941 06/56: removed unecessary line space in the code block, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle ac0458b251 10/56: Add package dependency to Package-Requires header, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle 34e63c2754 23/56: matched license in org-auto-tangle.el match that of License.org, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle 5ffbe41243 39/56: Add org-auto-tangle-default variable,
ELPA Syncer <=
- [nongnu] elpa/org-auto-tangle ec4341f844 47/56: moved (require 'org) to global instead of inline, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle 5da721fff9 40/56: Update readme to correct grammatical issues., ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle fbdd38d11e 55/56: Added Safe-list usage to readme, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle d3036a040a 12/56: moved the method definations to top level to remove error warnings, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle 2e4a664210 19/56: moved the anonymous function inside the hooks to a named function, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle eed3601f4b 25/56: added syntax highlighting and some spelling corrections, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle ade8d90ecf 34/56: changed quotes for functions with a sharp quote, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle dc7eb11e6a 45/56: Merge pull request #7 from zzamboni/master, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle 5d9f2734c9 54/56: Update License.org, ELPA Syncer, 2022/06/06
- [nongnu] elpa/org-auto-tangle cedd4dc41f 46/56: Update org-auto-tangle.el, ELPA Syncer, 2022/06/06