Browse Source

Rework `orgstruct++-mode' so that you can turn if off safely.

* org.el (org-auto-fill-fallback-function)
(org-indent-line-fallback-function)
(org-fill-paragraph-fallback-function)
(org-auto-fill-fallback-function)
(org-indent-line-fallback-function)
(org-fill-paragraph-fallback-function): Remove.
(org-fb-vars): New buffer-local variable.
(orgstruct++-mode): Use the fallback variable `org-fb-vars' to
store, use and restore variables if needed.
(org-fill-paragraph): Ignore `orgstruct++-mode' filling
variables when needed.
(org-auto-fill-function, org-indent-line-function): Ditto.

* org-macs.el (orgstruct++-ignore-org-filling): New macro.
Bastien Guerry 8 years ago
parent
commit
a8c3125a14
2 changed files with 28 additions and 20 deletions
  1. 6 0
      lisp/org-macs.el
  2. 22 20
      lisp/org.el

+ 6 - 0
lisp/org-macs.el

@@ -410,6 +410,12 @@ the value in cdr."
     (cons (list (car flat) (cadr flat))
          (org-make-parameter-alist (cddr flat)))))
 
+(defmacro orgstruct++-ignore-org-filling (&rest body)
+  "Ignore org filling in `orgstruct++-mode'."
+  `(let ,org-fb-vars
+     ,@body))
+(def-edebug-spec orgstruct++-ignore-org-filling (&optional ("quote" body)))
+
 (provide 'org-macs)
 
 ;;; org-macs.el ends here

+ 22 - 20
lisp/org.el

@@ -4943,12 +4943,6 @@ Stars are put in group 1 and the trimmed body in group 2.")
 
 (defvar bidi-paragraph-direction)
 (defvar buffer-face-mode-face)
-(defvar org-auto-fill-fallback-function nil)
-(defvar org-indent-line-fallback-function nil)
-(defvar org-fill-paragraph-fallback-function nil)
-(make-variable-buffer-local 'org-auto-fill-fallback-function)
-(make-variable-buffer-local 'org-indent-line-fallback-function)
-(make-variable-buffer-local 'org-fill-paragraph-fallback-function)
 
 ;;;###autoload
 (define-derived-mode org-mode outline-mode "Org"
@@ -8366,6 +8360,8 @@ C-c C-c     Set tags / toggle checkbox"
   "Unconditionally turn on `orgstruct-mode'."
   (orgstruct-mode 1))
 
+(defvar org-fb-vars nil)
+(make-variable-buffer-local 'org-fb-vars)
 (defun orgstruct++-mode (&optional arg)
   "Toggle `orgstruct-mode', the enhanced version of it.
 In addition to setting orgstruct-mode, this also exports all indentation
@@ -8375,14 +8371,15 @@ Note that turning off orgstruct-mode will *not* remove the
 indentation/paragraph settings.  This can only be done by refreshing the
 major mode, for example with \\[normal-mode]."
   (interactive "P")
-  (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1)))
-	;; Set fallback functions
-	org-auto-fill-fallback-function auto-fill-function
-	org-indent-line-fallback-function indent-line-function
-	org-fill-paragraph-fallback-function fill-paragraph-function)
+  (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
   (if (< arg 1)
-      (orgstruct-mode -1)
+      (progn (orgstruct-mode -1)
+	     (mapc (lambda(v)
+		     (org-set-local (car v)
+				    (if (eq (car-safe (cadr v)) 'quote) (cadadr v) (cadr v))))
+		   org-fb-vars))
     (orgstruct-mode 1)
+    (setq org-fb-vars nil)
     (let (var val)
       (mapc
        (lambda (x)
@@ -8390,6 +8387,7 @@ major mode, for example with \\[normal-mode]."
 		"^\\(paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
 		(symbol-name (car x)))
 	   (setq var (car x) val (nth 1 x))
+	   (push (list var `(quote ,(eval var))) org-fb-vars)
 	   (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
        org-local-vars)
       (org-set-local 'orgstruct-is-++ t))))
@@ -20402,11 +20400,13 @@ If point is in an inline task, mark that task instead."
 ;;; Paragraph filling stuff.
 ;; We want this to be just right, so use the full arsenal.
 
+(declare-function orgstruct++-ignore-org-filling "org-macs.el" (&rest body))
 (defun org-indent-line-function ()
   "Indent line depending on context."
   (interactive)
-  (if org-indent-line-fallback-function
-      (funcall org-indent-line-fallback-function)
+  (if orgstruct-is-++
+      (orgstruct++-ignore-org-filling
+       (funcall indent-line-function))
     (let* ((pos (point))
 	   (itemp (org-at-item-p))
 	   (case-fold-search t)
@@ -20709,8 +20709,11 @@ the functionality can be provided as a fall-back.")
 			       (save-excursion (forward-paragraph 1) (point)))
 	     (fill-paragraph justify) t))
 	  ;; Else falls back on `org-fill-paragraph-fallback-function'
-	  (org-fill-paragraph-fallback-function
-	   (funcall org-fill-paragraph-fallback-function justify))
+	  (orgstruct-is-++
+	   (orgstruct++-ignore-org-filling
+	    (fill-paragraph)))
+	  ;; (org-fill-paragraph-fallback-function
+	  ;;  (funcall org-fill-paragraph-fallback-function justify))
 	  ;; Else simply call `fill-paragraph'.
 	  (t nil))))
 
@@ -20754,10 +20757,9 @@ the functionality can be provided as a fall-back.")
 	     (setq prefix (make-string (org-list-item-body-column itemp) ?\ ))
 	     (flet ((fill-context-prefix (from to &optional flr) prefix))
 	       (do-auto-fill))))
-	  (org-auto-fill-fallback-function
-	   (let ((fill-prefix ""))
-	     (funcall org-auto-fill-fallback-function)))
-	  ;; Else just use `do-auto-fill'.
+	  (orgstruct-is-++
+	   (orgstruct++-ignore-org-filling
+	    (do-auto-fill)))
 	  (t (do-auto-fill)))))
 
 ;;; Other stuff.