From 075016cdfa0d008b643bf501402be24adaebf2ce Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 28 Feb 2011 12:31:56 -0700 Subject: [PATCH 1/8] ob-exp: resolve result hash in the original file * lisp/ob-exp.el (org-babel-exp-results): On export, ensure that the result hash is resolved in the original org-mode file. --- lisp/ob-exp.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index 67566d9dc..1e64758b8 100644 --- a/lisp/ob-exp.el +++ b/lisp/ob-exp.el @@ -248,7 +248,8 @@ This function is called by `org-babel-exp-do-export'. The code block will be evaluated. Optional argument SILENT can be used to inhibit insertion of results into the buffer." (when (and org-export-babel-evaluate - (not (equal hash (org-babel-result-hash)))) + (not (equal hash (org-babel-exp-in-export-file + (org-babel-result-hash))))) (let ((lang (nth 0 info)) (body (nth 1 info))) (setf (nth 2 info) (org-babel-exp-in-export-file From fcf66e74c6748b363b5a7a20a1f8e4ed77733c2a Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 28 Feb 2011 22:33:31 +0100 Subject: [PATCH 2/8] org-list: refactor code --- lisp/org-list.el | 159 +++++++++++++++++++++-------------------------- 1 file changed, 72 insertions(+), 87 deletions(-) diff --git a/lisp/org-list.el b/lisp/org-list.el index 8160fccbc..456052e82 100644 --- a/lisp/org-list.el +++ b/lisp/org-list.el @@ -476,8 +476,8 @@ This checks `org-list-ending-method'." "Is point in a line starting a hand-formatted item?" (save-excursion (beginning-of-line) - (and (not (eq (nth 2 (org-list-context)) 'invalid)) - (looking-at (org-item-re))))) + (and (looking-at (org-item-re)) + (not (eq (nth 2 (org-list-context)) 'invalid))))) (defun org-at-item-bullet-p () "Is point at the bullet of a plain list item?" @@ -514,89 +514,75 @@ Context will be a cell like (MIN MAX CONTEXT) where MIN and MAX are boundaries and CONTEXT is a symbol among `drawer', `block', `invalid', `inlinetask' and nil. -Contexts `block' and `invalid' refer to -`org-list-forbidden-blocks'." +Contexts `block' and `invalid' refer to `org-list-forbidden-blocks'." (save-match-data - (save-excursion - (beginning-of-line) - (let* ((outline-regexp (org-get-limited-outline-regexp)) - ;; Can't use org-drawers-regexp as this function might be - ;; called in buffers not in Org mode - (drawers-re (concat "^[ \t]*:\\(" - (mapconcat 'regexp-quote org-drawers "\\|") - "\\):[ \t]*$")) - (case-fold-search t) - ;; Compute position of surrounding headings. This is the - ;; default context. - (heading - (save-excursion - (list - (or (and (org-at-heading-p) (point-at-bol)) - (outline-previous-heading) - (point-min)) - (or (outline-next-heading) - (point-max)) - nil))) - (prev-head (car heading)) - (next-head (nth 1 heading)) - ;; Is point inside a drawer? - (drawerp - (when (and (org-in-regexps-block-p - drawers-re "^[ \t]*:END:" prev-head) - (save-excursion - (beginning-of-line) - (and (not (looking-at drawers-re)) - (not (looking-at "^[ \t]*:END:"))))) - (save-excursion - (list - (progn - (re-search-backward drawers-re prev-head t) - (1+ (point-at-eol))) - (if (re-search-forward "^[ \t]*:END:" next-head t) - (1- (point-at-bol)) - next-head) - 'drawer)))) - ;; Is point strictly in a block, and of which type? - (blockp - (save-excursion - (when (and (org-in-regexps-block-p - "^[ \t]*#\\+begin_" "^[ \t]*#\\+end_" prev-head) - (save-excursion - (beginning-of-line) - (not (looking-at - "^[ \t]*#\\+\\(begin\\|end\\)_")))) - (list - (progn - (re-search-backward - "^[ \t]*#\\+begin_\\(\\S-+\\)" prev-head t) - (1+ (point-at-eol))) - (save-match-data - (if (re-search-forward "^[ \t]*#\\+end_" next-head t) - (1- (point-at-bol)) - next-head)) - (if (member (downcase (match-string 1)) - org-list-forbidden-blocks) - 'invalid - 'block))))) - ;; Is point in an inlinetask? - (inlinetaskp - (when (and (featurep 'org-inlinetask) - (org-inlinetask-in-task-p) - (not (looking-at "^\\*+"))) - (save-excursion - (list - (progn (org-inlinetask-goto-beginning) - (1+ (point-at-eol))) - (progn - (org-inlinetask-goto-end) - (forward-line -1) - (1- (point-at-bol))) - 'inlinetask)))) - ;; List actual candidates - (context-list - (delq nil (list heading drawerp blockp inlinetaskp)))) - ;; Return the closest context around - (assq (apply 'max (mapcar 'car context-list)) context-list))))) + (org-with-limited-levels + (beginning-of-line) + (let* ((case-fold-search t) (pos (point)) beg end + ;; Compute position of surrounding headings. This is the + ;; default context. + (heading + (save-excursion + (list (or (and (org-at-heading-p) (point-at-bol)) + (outline-previous-heading) + (point-min)) + (or (outline-next-heading) (point-max)) + nil))) + (prev-head (car heading)) + (next-head (nth 1 heading)) + ;; Is point inside a drawer? + (drawerp + (save-excursion + (let ((end-re "^[ \t]*:END:") + ;; Can't use org-drawers-regexp as this function + ;; might be called in buffers not in Org mode + (drawers-re (concat "^[ \t]*:\\(" + (mapconcat 'regexp-quote org-drawers "\\|") + "\\):[ \t]*$"))) + (and (not (looking-at drawers-re)) + (not (looking-at end-re)) + (setq beg (and (re-search-backward drawers-re prev-head t) + (1+ (point-at-eol)))) + (setq end (or (and (re-search-forward end-re next-head t) + (1- (match-beginning 0))) + next-head)) + (>= end pos) + (list beg end 'drawer))))) + ;; Is point strictly in a block, and of which type? + (blockp + (save-excursion + (let ((block-re "^[ \t]*#\\+\\(begin\\|end\\)_") type) + (and (not (looking-at block-re)) + (setq beg (and (re-search-backward block-re prev-head t) + (1+ (point-at-eol)))) + (looking-at "^[ \t]*#\\+begin_\\(\\S-+\\)") + (setq type (downcase (match-string 1))) + (goto-char beg) + (setq end (or (and (re-search-forward block-re next-head t) + (1- (point-at-bol))) + next-head)) + (>= end pos) + (equal (downcase (match-string 1)) "end") + (list beg end (if (member type org-list-forbidden-blocks) + 'invalid 'block)))))) + ;; Is point in an inlinetask? + (inlinetaskp + (when (featurep 'org-inlinetask) + (save-excursion + (let* ((stars-re (org-inlinetask-outline-regexp)) + (end-re (concat stars-re "END[ \t]*$"))) + (and (not (looking-at "^\\*+")) + (setq beg (and (re-search-backward stars-re prev-head t) + (1+ (point-at-eol)))) + (not (looking-at end-re)) + (setq end (and (re-search-forward end-re next-head t) + (1- (match-beginning 0)))) + (> (point) pos) + (list beg end 'inlinetask)))))) + ;; List actual candidates + (context-list (delq nil (list heading drawerp blockp inlinetaskp)))) + ;; Return the closest context around + (assq (apply 'max (mapcar 'car context-list)) context-list))))) (defun org-list-struct () "Return structure of list at point. @@ -1197,8 +1183,7 @@ This function modifies STRUCT." ;; 4. Insert effectively item into buffer (goto-char item) (org-indent-to-column ind) - (insert body) - (insert item-sep) + (insert body item-sep) ;; 5. Add new item to STRUCT. (mapc (lambda (e) (let ((p (car e)) @@ -1238,7 +1223,7 @@ This function modifies STRUCT." ;; SIZE-OFFSET. (t (setcar e (+ p size-offset)) (setcar (nthcdr 6 e) (+ end size-offset)))))) - struct) + struct) (push (list item ind bullet nil box nil (+ item item-size)) struct) (setq struct (sort struct (lambda (e1 e2) (< (car e1) (car e2))))) ;; 6. If not BEFOREP, new item must appear after ITEM, so From c70e601b1efb52a9624c337928ccbdefd2e6cba3 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 28 Feb 2011 16:03:03 -0700 Subject: [PATCH 3/8] ob-table: fix bug returning an integer from sbe * lisp/ob-table.el (sbe): Ensure that ob-trim is only called on strings. --- lisp/ob-table.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/ob-table.el b/lisp/ob-table.el index ae444efd0..c76ef3c5f 100644 --- a/lisp/ob-table.el +++ b/lisp/ob-table.el @@ -97,7 +97,8 @@ example above." variables))) (unless (stringp source-block) (setq source-block (symbol-name source-block))) - (org-babel-trim + ((lambda (result) + (org-babel-trim (if (stringp result) result (format "%S" result)))) (if (and source-block (> (length source-block) 0)) (let ((params (eval `(org-babel-parse-header-arguments From be0b3ca1ca28a2ad90fa5b71c899c5f067575584 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 27 Feb 2011 08:47:36 -0700 Subject: [PATCH 4/8] ob: inhibit lisp evaluation of values read from tables and lists * lisp/ob.el (org-babel-read-table): Inhibit lisp evaluation of values when reading from tables. (org-babel-read-list): Inhibit lisp evaluation of values when reading from lists. (org-babel-read): Add optional argument which can be used to inhibit lisp evaluation of value. --- lisp/ob.el | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lisp/ob.el b/lisp/ob.el index 8633b7336..b919a837e 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -1393,12 +1393,13 @@ following the source block." "Read the table at `point' into emacs-lisp." (mapcar (lambda (row) (if (and (symbolp row) (equal row 'hline)) row - (mapcar #'org-babel-read row))) + (mapcar (lambda (el) (org-babel-read el 'inhibit-lisp-eval)) row))) (org-table-to-lisp))) (defun org-babel-read-list () "Read the list at `point' into emacs-lisp." - (mapcar #'org-babel-read (mapcar #'cadr (cdr (org-list-parse-list))))) + (mapcar (lambda (el) (org-babel-read el 'inhibit-lisp-eval)) + (mapcar #'cadr (cdr (org-list-parse-list))))) (defvar org-link-types-re) (defun org-babel-read-link () @@ -1908,18 +1909,18 @@ block but are passed literally to the \"example-block\"." (apply #'string (reverse out))))) str)))) -(defun org-babel-read (cell) +(defun org-babel-read (cell &optional inhibit-lisp-eval) "Convert the string value of CELL to a number if appropriate. -Otherwise if cell looks like lisp (meaning it starts with a -\"(\" or a \"'\") then read it as lisp, otherwise return it -unmodified as a string. - -This is taken almost directly from `org-read-prop'." +Otherwise if cell looks like lisp (meaning it starts with a \"(\" +or a \"'\") then read it as lisp, otherwise return it unmodified +as a string. Optional argument NO-LISP-EVAL inhibits lisp +evaluation for situations in which is it not appropriate." (if (and (stringp cell) (not (equal cell ""))) (or (org-babel-number-p cell) - (if (or (equal "(" (substring cell 0 1)) - (equal "'" (substring cell 0 1)) - (equal "`" (substring cell 0 1))) + (if (and (not inhibit-lisp-eval) + (or (equal "(" (substring cell 0 1)) + (equal "'" (substring cell 0 1)) + (equal "`" (substring cell 0 1)))) (eval (read cell)) (progn (set-text-properties 0 (length cell) nil cell) cell))) cell)) From aaf0e2d6bb1a24c26a691b86e8c98b81547ae87a Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Tue, 1 Mar 2011 07:24:14 +0100 Subject: [PATCH 5/8] Get rid of some compiler warnings * Makefile (lisp/org-special-blocks.elc): Add dependency on org-compat.el * lisp/ob-ref.el (org-at-item-p): Declare function. * lisp/org-agenda.el (diary-time-regexp): defvar. * lisp/org-archive.el (org-archive-subtree): Bind local variable `infile-p'. * lisp/org-capture.el (org-capture-insert-template-here): Get template text from property list, to avoid byte compiler message. * lisp/org-latex.el (org-export-latex-tables): Bind local variable `width'. * lisp/org-special-blocks.el (org-compat): Add require statement. * lisp/org-table.el (orgtbl-ctrl-c-ctrl-c): Bind local variable `const-str'. * lisp/org.el (org-eval): Moved function here from org-agenda.el. --- Makefile | 1 + lisp/ob-ref.el | 1 + lisp/org-agenda.el | 8 +------- lisp/org-archive.el | 2 +- lisp/org-capture.el | 2 +- lisp/org-latex.el | 2 +- lisp/org-special-blocks.el | 2 ++ lisp/org-table.el | 2 +- lisp/org.el | 6 ++++++ 9 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index ca9bcca47..b3fa19fe3 100644 --- a/Makefile +++ b/Makefile @@ -503,6 +503,7 @@ lisp/org-publish.elc: lisp/org-protocol.elc: lisp/org.el lisp/org-remember.elc: lisp/org.el lisp/org-rmail.elc: lisp/org.el +lisp/org-special-blocks.elc: lisp/org-compat.el lisp/org-src.elc: lisp/org-macs.el lisp/org-compat.el lisp/org-table.elc: lisp/org.el lisp/org-taskjuggler.elc: lisp/org.el lisp/org-exp.el diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el index 31944fd30..aa718b305 100644 --- a/lisp/ob-ref.el +++ b/lisp/ob-ref.el @@ -57,6 +57,7 @@ (declare-function org-at-table-p "org" (&optional table-type)) (declare-function org-count "org" (CL-ITEM CL-SEQ)) (declare-function org-in-item-p "org-list" ()) +(declare-function org-at-item-p "org-list" ()) (defvar org-babel-ref-split-regexp "[ \f\t\n\r\v]*\\(.+?\\)[ \f\t\n\r\v]*=[ \f\t\n\r\v]*\\(.+\\)[ \f\t\n\r\v]*") diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index dee23e002..91dff40bc 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -4307,7 +4307,7 @@ of what a project is and how to check if it stuck, customize the variable (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param. (defvar list-diary-entries-hook) - +(defvar diary-time-regexp) (defun org-get-entries-from-diary (date) "Get the (Emacs Calendar) diary entries for DATE." (require 'diary-lib) @@ -5473,12 +5473,6 @@ The modified list may contain inherited tags, and tags matched by (append new list) (append list new))))) -(defun org-eval (form) - "Eval FORM and return result." - (condition-case error - (eval form) - (error (format "%%![Error: %s]" error)))) - (defun org-compile-prefix-format (key) "Compile the prefix format into a Lisp form that can be evaluated. The resulting form is returned and stored in the variable diff --git a/lisp/org-archive.el b/lisp/org-archive.el index a98471479..c70616661 100644 --- a/lisp/org-archive.el +++ b/lisp/org-archive.el @@ -211,7 +211,7 @@ this heading." (current-time))) category todo priority ltags itags atags ;; end of variables that will be used for saving context - location afile heading buffer level newfile-p visiting) + location afile heading buffer level newfile-p infile-p visiting) ;; Find the local archive location (setq location (org-get-local-archive-location) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index e9a851e7b..1390f2143 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1054,7 +1054,7 @@ Point will remain at the first line after the inserted text." (setq beg (point)) (cond ((and (eq type 'entry) (org-mode-p)) - (org-capture-verify-tree txt) + (org-capture-verify-tree (org-capture-get :template)) (org-paste-subtree nil template t)) ((and (memq type '(item checkitem)) (org-mode-p) diff --git a/lisp/org-latex.el b/lisp/org-latex.el index 303eb6e38..d9e0e3fdf 100644 --- a/lisp/org-latex.el +++ b/lisp/org-latex.el @@ -1817,7 +1817,7 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." (org-table-last-column-widths (copy-sequence org-table-last-column-widths)) fnum fields line lines olines gr colgropen line-fmt align - caption shortn label attr floatp placement + caption width shortn label attr floatp placement longtblp tblenv tabular-env) (if org-export-latex-tables-verbatim (let* ((tbl (concat "\\begin{verbatim}\n" raw-table diff --git a/lisp/org-special-blocks.el b/lisp/org-special-blocks.el index 54fb6cb39..fa59657e6 100644 --- a/lisp/org-special-blocks.el +++ b/lisp/org-special-blocks.el @@ -40,6 +40,8 @@ ;; user to add this class to his or her stylesheet if this div is to ;; mean anything. +(require 'org-compat) + (defvar org-special-blocks-ignore-regexp "^\\(LaTeX\\|HTML\\)$" "A regexp indicating the names of blocks that should be ignored by org-special-blocks. These blocks will presumably be diff --git a/lisp/org-table.el b/lisp/org-table.el index 5d7c66734..56d927eef 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -3715,7 +3715,7 @@ to execute outside of tables." If it is a table to be sent away to a receiver, do it. With prefix arg, also recompute table." (interactive "P") - (let ((pos (point)) action consts-str consts cst) + (let ((pos (point)) action consts-str consts cst const-str) (save-excursion (beginning-of-line 1) (setq action (cond diff --git a/lisp/org.el b/lisp/org.el index 03f0b72fc..a26a3caad 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -18201,6 +18201,12 @@ With prefix arg UNCOMPILED, load the uncompiled versions." (display-buffer buf) (sit-for 0)))) +(defun org-eval (form) + "Eval FORM and return result." + (condition-case error + (eval form) + (error (format "%%![Error: %s]" error)))) + (defun org-in-commented-line () "Is point in a line starting with `#'?" (equal (char-after (point-at-bol)) ?#)) From 5726eb067647909ea7510b63bba6feee7acd4543 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Tue, 1 Mar 2011 07:27:57 +0100 Subject: [PATCH 6/8] Bind some local variables * lisp/org-agenda.el (org-agenda-get-scheduled): (org-agenda-get-timestamps): Bind local variable `show-all'. --- lisp/org-agenda.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 91dff40bc..ea822da3d 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -4695,7 +4695,7 @@ This function is invoked if `org-agenda-todo-ignore-deadlines', "\\|\\(<%%\\(([^>\n]+)\\)>\\)")) marker hdmarker deadlinep scheduledp clockp closedp inactivep donep tmp priority category ee txt timestr tags b0 b3 e3 head - todo-state end-of-match) + todo-state end-of-match show-all) (goto-char (point-min)) (while (setq end-of-match (re-search-forward regexp nil t)) (setq b0 (match-beginning 0) @@ -5051,7 +5051,7 @@ FRACTION is what fraction of the head-warning time has passed." (cons (marker-position mm) a))) deadline-results)) d2 diff pos pos1 category tags donep - ee txt head pastschedp todo-state face timestr s habitp) + ee txt head pastschedp todo-state face timestr s habitp show-all) (goto-char (point-min)) (while (re-search-forward regexp nil t) (catch :skip From 3805b2c4e46f8efb4df7ad2f4c7a196a09d42a54 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Tue, 1 Mar 2011 07:30:43 +0100 Subject: [PATCH 7/8] Defvar a dynamically scoped variable * lisp/org-exp-blocks.el (backend): defvar. --- lisp/org-exp-blocks.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lisp/org-exp-blocks.el b/lisp/org-exp-blocks.el index 062e0622d..df41c4014 100644 --- a/lisp/org-exp-blocks.el +++ b/lisp/org-exp-blocks.el @@ -76,6 +76,8 @@ (require 'cl)) (require 'org) +(defvar backend) ; dynamically scoped from caller + (defvar org-exp-blocks-block-regexp (concat "^\\([ \t]*\\)#\\+begin_\\(\\S-+\\)" From c895af44d4e2ff9408ac54dafaa58e8d057efff5 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Tue, 1 Mar 2011 08:08:36 +0100 Subject: [PATCH 8/8] Fix some compiler warnings * lisp/ob.el (org-src-lang-modes): Defvar. (org-at-item-p): Declare function. * lisp/ob-calc.el (calc-store): Require. (var-syms): Defvar. * lisp/ob-python.el (py-default-interpreter): Defvar. --- lisp/ob-calc.el | 2 ++ lisp/ob-python.el | 1 + lisp/ob.el | 2 ++ 3 files changed, 5 insertions(+) diff --git a/lisp/ob-calc.el b/lisp/ob-calc.el index b1f8e8088..f937def55 100644 --- a/lisp/ob-calc.el +++ b/lisp/ob-calc.el @@ -29,6 +29,7 @@ ;;; Code: (require 'ob) (require 'calc) +(require 'calc-store) (unless (featurep 'xemacs) (require 'calc-trail)) (eval-when-compile (require 'ob-comint)) @@ -83,6 +84,7 @@ (with-current-buffer (get-buffer "*Calculator*") (calc-eval (calc-top 1))))) +(defvar var-syms) ; Dynamically scoped from org-babel-execute:calc (defun ob-calc-maybe-resolve-var (el) (if (consp el) (if (and (equal 'var (car el)) (member (cadr el) var-syms)) diff --git a/lisp/ob-python.el b/lisp/ob-python.el index db1d865a2..5bedbf8b4 100644 --- a/lisp/ob-python.el +++ b/lisp/ob-python.el @@ -130,6 +130,7 @@ Emacs-lisp table, otherwise return the results as a string." "Return the buffer associated with SESSION." (cdr (assoc session org-babel-python-buffers))) +(defvar py-default-interpreter) (defun org-babel-python-initiate-session-by-key (&optional session) "Initiate a python session. If there is not a current inferior-process-buffer in SESSION diff --git a/lisp/ob.el b/lisp/ob.el index b919a837e..ea1c9686b 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -35,6 +35,7 @@ (require 'org-macs) (defvar org-babel-call-process-region-original) +(defvar org-src-lang-modes) (declare-function show-all "outline" ()) (declare-function tramp-compat-make-temp-file "tramp-compat" (filename &optional dir-flag)) @@ -74,6 +75,7 @@ (declare-function org-babel-lob-execute-maybe "ob-lob" ()) (declare-function org-number-sequence "org-compat" (from &optional to inc)) (declare-function org-in-item-p "org-list" ()) +(declare-function org-at-item-p "org-list" ()) (declare-function org-list-parse-list "org-list" (&optional delete)) (declare-function org-list-to-generic "org-list" (LIST PARAMS)) (declare-function org-list-struct "org-list" ())