0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-08-26 12:32:53 +00:00

Merge branch 'master' of git+ssh://repo.or.cz/srv/git/org-mode

This commit is contained in:
Carsten Dominik 2010-11-20 00:11:46 +01:00
commit 967c71f5ef
7 changed files with 137 additions and 110 deletions

View file

@ -11758,8 +11758,8 @@ another by commas, as shown in the following example.
@node results, file, var, Specific header arguments @node results, file, var, Specific header arguments
@subsubsection @code{:results} @subsubsection @code{:results}
There are three classes of @code{:results} header argument. Only one option of There are three classes of @code{:results} header argument. Only one option
each type may be supplied per code block. per class may be supplied per code block.
@itemize @bullet @itemize @bullet
@item @item
@ -11802,6 +11802,9 @@ table or scalar depending on their value.
The results should be interpreted as an Org-mode table. If a single value is The results should be interpreted as an Org-mode table. If a single value is
returned, it will be converted into a table with one row and one column. returned, it will be converted into a table with one row and one column.
E.g., @code{:results value table}. E.g., @code{:results value table}.
@item @code{list}
The results should be interpreted as an Org-mode list. If a single scalar
value is returned it will be converted into a list with only one element.
@item @code{scalar}, @code{verbatim} @item @code{scalar}, @code{verbatim}
The results should be interpreted literally---they will not be The results should be interpreted literally---they will not be
converted into a table. The results will be inserted into the Org-mode converted into a table. The results will be inserted into the Org-mode

View file

@ -147,6 +147,7 @@ the variable."
(case type (case type
('results-line (org-babel-read-result)) ('results-line (org-babel-read-result))
('table (org-babel-read-table)) ('table (org-babel-read-table))
('list (org-babel-read-list))
('file (org-babel-read-link)) ('file (org-babel-read-link))
('source-block (org-babel-execute-src-block nil nil params)) ('source-block (org-babel-execute-src-block nil nil params))
('lob (org-babel-execute-src-block nil lob-info params))))) ('lob (org-babel-execute-src-block nil lob-info params)))))
@ -214,6 +215,7 @@ to \"0:-1\"."
Return nil if none of the supported reference types are found. Return nil if none of the supported reference types are found.
Supported reference types are tables and source blocks." Supported reference types are tables and source blocks."
(cond ((org-at-table-p) 'table) (cond ((org-at-table-p) 'table)
((org-in-item-p) 'list)
((looking-at "^[ \t]*#\\+BEGIN_SRC") 'source-block) ((looking-at "^[ \t]*#\\+BEGIN_SRC") 'source-block)
((looking-at org-bracket-link-regexp) 'file) ((looking-at org-bracket-link-regexp) 'file)
((looking-at org-babel-result-regexp) 'results-line))) ((looking-at org-babel-result-regexp) 'results-line)))

View file

@ -28,6 +28,7 @@
;;; Code: ;;; Code:
(require 'ob) (require 'ob)
(require 'ob-eval)
(require 'ob-ref) (require 'ob-ref)
(declare-function org-fill-template "org" (template alist)) (declare-function org-fill-template "org" (template alist))
@ -65,15 +66,10 @@ This function is called by `org-babel-execute-src-block'."
(unless db (error "ob-sqlite: can't evaluate without a database.")) (unless db (error "ob-sqlite: can't evaluate without a database."))
(with-temp-buffer (with-temp-buffer
(insert (insert
(shell-command-to-string (org-babel-eval
(org-fill-template (org-fill-template
"%cmd -init %body %header %separator %nullvalue %others %csv %db " "%cmd %header %separator %nullvalue %others %csv %db "
(list (list
(cons "body" ((lambda (sql-file)
(with-temp-file sql-file
(insert (org-babel-expand-body:sqlite body params)))
sql-file)
(org-babel-temp-file "sqlite-sql-")))
(cons "cmd" org-babel-sqlite3-command) (cons "cmd" org-babel-sqlite3-command)
(cons "header" (if headers-p "-header" "-noheader")) (cons "header" (if headers-p "-header" "-noheader"))
(cons "separator" (cons "separator"
@ -90,7 +86,9 @@ This function is called by `org-babel-execute-src-block'."
(member :html others) separator) (member :html others) separator)
"" ""
"-csv")) "-csv"))
(cons "db " db))))) (cons "db " db)))
;; body of the code block
(org-babel-expand-body:sqlite body params)))
(if (or (member "scalar" result-params) (if (or (member "scalar" result-params)
(member "html" result-params) (member "html" result-params)
(member "code" result-params) (member "code" result-params)

View file

@ -125,6 +125,7 @@ evaluating BODY."
This function exports the source code using This function exports the source code using
`org-babel-tangle' and then loads the resulting file using `org-babel-tangle' and then loads the resulting file using
`load-file'." `load-file'."
(interactive "fFile to load: ")
(flet ((age (file) (flet ((age (file)
(float-time (float-time
(time-subtract (current-time) (time-subtract (current-time)

View file

@ -584,6 +584,60 @@ results already exist."
(insert (echo-res results)))))) (insert (echo-res results))))))
t))) t)))
;;;###autoload
(defmacro org-babel-map-src-blocks (file &rest body)
"Evaluate BODY forms on each source-block in FILE.
If FILE is nil evaluate BODY forms on source blocks in current
buffer. During evaluation of BODY the following local variables
are set relative to the currently matched code block.
full-block ------- string holding the entirety of the code block
beg-block -------- point at the beginning of the code block
end-block -------- point at the end of the matched code block
lang ------------- string holding the language of the code block
beg-lang --------- point at the beginning of the lang
end-lang --------- point at the end of the lang
switches --------- string holding the switches
beg-switches ----- point at the beginning of the switches
end-switches ----- point at the end of the switches
header-args ------ string holding the header-args
beg-header-args -- point at the beginning of the header-args
end-header-args -- point at the end of the header-args
body ------------- string holding the body of the code block
beg-body --------- point at the beginning of the body
end-body --------- point at the end of the body"
(declare (indent 1))
(let ((tempvar (make-symbol "file")))
`(let* ((,tempvar ,file)
(visited-p (or (null ,tempvar)
(get-file-buffer (expand-file-name ,tempvar))))
(point (point)) to-be-removed)
(save-window-excursion
(when ,tempvar (find-file ,tempvar))
(setq to-be-removed (current-buffer))
(goto-char (point-min))
(while (re-search-forward org-babel-src-block-regexp nil t)
(goto-char (match-beginning 0))
(let ((full-block (match-string 0))
(beg-block (match-beginning 0))
(end-block (match-end 0))
(lang (match-string 2))
(beg-lang (match-beginning 2))
(end-lang (match-end 2))
(switches (match-string 3))
(beg-switches (match-beginning 3))
(end-switches (match-end 3))
(header-args (match-string 4))
(beg-header-args (match-beginning 4))
(end-header-args (match-end 4))
(body (match-string 5))
(beg-body (match-beginning 5))
(end-body (match-end 5)))
,@body
(goto-char end-block))))
(unless visited-p (kill-buffer to-be-removed))
(goto-char point))))
;;;###autoload ;;;###autoload
(defun org-babel-execute-buffer (&optional arg) (defun org-babel-execute-buffer (&optional arg)
"Execute source code blocks in a buffer. "Execute source code blocks in a buffer.
@ -758,57 +812,6 @@ portions of results lines."
(lambda () (org-add-hook 'change-major-mode-hook (lambda () (org-add-hook 'change-major-mode-hook
'org-babel-show-result-all 'append 'local))) 'org-babel-show-result-all 'append 'local)))
(defmacro org-babel-map-src-blocks (file &rest body)
"Evaluate BODY forms on each source-block in FILE.
If FILE is nil evaluate BODY forms on source blocks in current
buffer. During evaluation of BODY the following local variables
are set relative to the currently matched code block.
full-block ------- string holding the entirety of the code block
beg-block -------- point at the beginning of the code block
end-block -------- point at the end of the matched code block
lang ------------- string holding the language of the code block
beg-lang --------- point at the beginning of the lang
end-lang --------- point at the end of the lang
switches --------- string holding the switches
beg-switches ----- point at the beginning of the switches
end-switches ----- point at the end of the switches
header-args ------ string holding the header-args
beg-header-args -- point at the beginning of the header-args
end-header-args -- point at the end of the header-args
body ------------- string holding the body of the code block
beg-body --------- point at the beginning of the body
end-body --------- point at the end of the body"
(declare (indent 1))
`(let ((visited-p (or (null ,file)
(get-file-buffer (expand-file-name ,file))))
(point (point)) to-be-removed)
(save-window-excursion
(when ,file (find-file ,file))
(setq to-be-removed (current-buffer))
(goto-char (point-min))
(while (re-search-forward org-babel-src-block-regexp nil t)
(goto-char (match-beginning 0))
(let ((full-block (match-string 0))
(beg-block (match-beginning 0))
(end-block (match-end 0))
(lang (match-string 2))
(beg-lang (match-beginning 2))
(end-lang (match-end 2))
(switches (match-string 3))
(beg-switches (match-beginning 3))
(end-switches (match-end 3))
(header-args (match-string 4))
(beg-header-args (match-beginning 4))
(end-header-args (match-end 4))
(body (match-string 5))
(beg-body (match-beginning 5))
(end-body (match-end 5)))
,@body
(goto-char end-block))))
(unless visited-p (kill-buffer to-be-removed))
(goto-char point)))
(defvar org-file-properties) (defvar org-file-properties)
(defun org-babel-params-from-properties (&optional lang) (defun org-babel-params-from-properties (&optional lang)
"Retrieve parameters specified as properties. "Retrieve parameters specified as properties.
@ -1307,6 +1310,7 @@ following the source block."
(let ((case-fold-search t) result-string) (let ((case-fold-search t) result-string)
(cond (cond
((org-at-table-p) (org-babel-read-table)) ((org-at-table-p) (org-babel-read-table))
((org-in-item-p) (org-babel-read-list))
((looking-at org-bracket-link-regexp) (org-babel-read-link)) ((looking-at org-bracket-link-regexp) (org-babel-read-link))
((looking-at org-block-regexp) (org-babel-trim (match-string 4))) ((looking-at org-block-regexp) (org-babel-trim (match-string 4)))
((looking-at "^[ \t]*: ") ((looking-at "^[ \t]*: ")
@ -1332,6 +1336,10 @@ following the source block."
(mapcar #'org-babel-read row))) (mapcar #'org-babel-read row)))
(org-table-to-lisp))) (org-table-to-lisp)))
(defun org-babel-read-list ()
"Read the list at `point' into emacs-lisp."
(mapcar #'org-babel-read (cdr (org-list-parse-list))))
(defvar org-link-types-re) (defvar org-link-types-re)
(defun org-babel-read-link () (defun org-babel-read-link ()
"Read the link at `point' into emacs-lisp. "Read the link at `point' into emacs-lisp.
@ -1365,7 +1373,9 @@ silent -- no results are inserted
file ---- the results are interpreted as a file path, and are file ---- the results are interpreted as a file path, and are
inserted into the buffer using the Org-mode file syntax inserted into the buffer using the Org-mode file syntax
raw ----- results are added directly to the org-mode file. This list ---- the results are interpreted as an Org-mode list.
raw ----- results are added directly to the Org-mode file. This
is a good option if you code block will output org-mode is a good option if you code block will output org-mode
formatted text. formatted text.
@ -1430,6 +1440,13 @@ code ---- the results are extracted in the syntax of the source
(cond (cond
;; do nothing for an empty result ;; do nothing for an empty result
((= (length result) 0)) ((= (length result) 0))
;; insert a list if preferred
((member "list" result-params)
(insert
(org-babel-trim
(org-list-to-generic (cons 'unordered
(if (listp result) result (list result)))
'(:splicep nil :istart "- " :iend "\n")))))
;; assume the result is a table if it's not a string ;; assume the result is a table if it's not a string
((not (stringp result)) ((not (stringp result))
(insert (concat (orgtbl-to-orgtbl (insert (concat (orgtbl-to-orgtbl
@ -1482,8 +1499,10 @@ code ---- the results are extracted in the syntax of the source
(defun org-babel-result-end () (defun org-babel-result-end ()
"Return the point at the end of the current set of results" "Return the point at the end of the current set of results"
(save-excursion (save-excursion
(if (org-at-table-p) (cond
(progn (goto-char (org-table-end)) (point)) ((org-at-table-p) (progn (goto-char (org-table-end)) (point)))
((org-in-item-p) (- (org-list-bottom-point) 1))
(t
(let ((case-fold-search t)) (let ((case-fold-search t))
(cond (cond
((looking-at "[ \t]*#\\+begin_latex") ((looking-at "[ \t]*#\\+begin_latex")
@ -1500,7 +1519,7 @@ code ---- the results are extracted in the syntax of the source
(forward-line 1)) (forward-line 1))
(t (progn (while (looking-at "[ \t]*\\(: \\|\\[\\[\\)") (t (progn (while (looking-at "[ \t]*\\(: \\|\\[\\[\\)")
(forward-line 1)))))) (forward-line 1))))))
(point)))) (point)))))
(defun org-babel-result-to-file (result) (defun org-babel-result-to-file (result)
"Convert RESULT into an `org-mode' link. "Convert RESULT into an `org-mode' link.
@ -1550,7 +1569,7 @@ Later elements of PLISTS override the values of previous element.
This takes into account some special considerations for certain This takes into account some special considerations for certain
parameters when merging lists." parameters when merging lists."
(let ((results-exclusive-groups (let ((results-exclusive-groups
'(("file" "vector" "table" "scalar" "raw" "org" '(("file" "list" "vector" "table" "scalar" "raw" "org"
"html" "latex" "code" "pp") "html" "latex" "code" "pp")
("replace" "silent" "append" "prepend") ("replace" "silent" "append" "prepend")
("output" "value"))) ("output" "value")))

View file

@ -1629,35 +1629,36 @@ If WHICH is a valid string, use that as the new bullet. If WHICH
is an integer, 0 means `-', 1 means `+' etc. If WHICH is is an integer, 0 means `-', 1 means `+' etc. If WHICH is
'previous, cycle backwards." 'previous, cycle backwards."
(interactive "P") (interactive "P")
(let* ((top (org-list-top-point)) (save-excursion
(bullet (save-excursion (let* ((top (org-list-top-point))
(goto-char (org-get-beginning-of-list top)) (bullet (progn
(org-get-bullet))) (goto-char (org-get-beginning-of-list top))
(current (cond (org-get-bullet)))
((string-match "\\." bullet) "1.") (current (cond
((string-match ")" bullet) "1)") ((string-match "\\." bullet) "1.")
(t bullet))) ((string-match ")" bullet) "1)")
(bullet-rule-p (cdr (assq 'bullet org-list-automatic-rules))) (t bullet)))
(bullet-list (append '("-" "+" ) (bullet-rule-p (cdr (assq 'bullet org-list-automatic-rules)))
;; *-bullets are not allowed at column 0 (bullet-list (append '("-" "+" )
(unless (and bullet-rule-p ;; *-bullets are not allowed at column 0
(looking-at "\\S-")) '("*")) (unless (and bullet-rule-p
;; Description items cannot be numbered (looking-at "\\S-")) '("*"))
(unless (and bullet-rule-p ;; Description items cannot be numbered
(or (eq org-plain-list-ordered-item-terminator ?\)) (unless (and bullet-rule-p
(org-at-item-description-p))) '("1.")) (or (eq org-plain-list-ordered-item-terminator ?\))
(unless (and bullet-rule-p (org-at-item-description-p))) '("1."))
(or (eq org-plain-list-ordered-item-terminator ?.) (unless (and bullet-rule-p
(org-at-item-description-p))) '("1)")))) (or (eq org-plain-list-ordered-item-terminator ?.)
(len (length bullet-list)) (org-at-item-description-p))) '("1)"))))
(item-index (- len (length (member current bullet-list)))) (len (length bullet-list))
(get-value (lambda (index) (nth (mod index len) bullet-list))) (item-index (- len (length (member current bullet-list))))
(new (cond (get-value (lambda (index) (nth (mod index len) bullet-list)))
((member which bullet-list) which) (new (cond
((numberp which) (funcall get-value which)) ((member which bullet-list) which)
((eq 'previous which) (funcall get-value (1- item-index))) ((numberp which) (funcall get-value which))
(t (funcall get-value (1+ item-index)))))) ((eq 'previous which) (funcall get-value (1- item-index)))
(org-list-repair new top))) (t (funcall get-value (1+ item-index))))))
(org-list-repair new top))))
;;; Checkboxes ;;; Checkboxes

View file

@ -18553,7 +18553,7 @@ which make use of the date at the cursor."
;; We want this to be just right, so use the full arsenal. ;; We want this to be just right, so use the full arsenal.
(defun org-indent-line-function () (defun org-indent-line-function ()
"Indent line like previous, but further if previous was headline or item." "Indent line depending on context."
(interactive) (interactive)
(let* ((pos (point)) (let* ((pos (point))
(itemp (org-at-item-p)) (itemp (org-at-item-p))
@ -18562,13 +18562,15 @@ which make use of the date at the cursor."
(inline-task-p (and (featurep 'org-inlinetask) (inline-task-p (and (featurep 'org-inlinetask)
(org-inlinetask-in-task-p))) (org-inlinetask-in-task-p)))
column bpos bcol tpos tcol) column bpos bcol tpos tcol)
;; Find the previous relevant line
(beginning-of-line 1) (beginning-of-line 1)
(cond (cond
;; Comments ;; Comments
((looking-at "#") (setq column 0)) ((looking-at "# ") (setq column 0))
;; Headings ;; Headings
((looking-at "\\*+ ") (setq column 0)) ((looking-at "\\*+ ") (setq column 0))
;; Literal examples
((looking-at "[ \t]*:[ \t]")
(setq column (org-get-indentation))) ; do nothing
;; Drawers ;; Drawers
((and (looking-at "[ \t]*:END:") ((and (looking-at "[ \t]*:END:")
(save-excursion (re-search-backward org-drawer-regexp nil t))) (save-excursion (re-search-backward org-drawer-regexp nil t)))
@ -18601,20 +18603,23 @@ which make use of the date at the cursor."
(setq tcol (+ bcol 5))) (setq tcol (+ bcol 5)))
(goto-char pos) (goto-char pos)
(setq column (if itemp (org-get-indentation) tcol))) (setq column (if itemp (org-get-indentation) tcol)))
;; This line has nothing special, look upside to get a clue about ;; This line has nothing special, look at the previous relevant
;; what to do. ;; line to compute indentation
(t (t
(beginning-of-line 0) (beginning-of-line 0)
(while (and (not (bobp)) (while (and (not (bobp))
(not (looking-at org-drawer-regexp))
;; skip comments, verbatim, empty lines, tables, ;; skip comments, verbatim, empty lines, tables,
;; inline tasks ;; inline tasks, lists, drawers and blocks
(or (looking-at "[ \t]*[\n:#|]") (or (and (looking-at "[ \t]*:END:")
(re-search-backward org-drawer-regexp nil t))
(and (looking-at "[ \t]*#\\+end_")
(re-search-backward "[ \t]*#\\+begin_"nil t))
(looking-at "[ \t]*[\n:#|]")
(and (org-in-item-p) (goto-char (org-list-top-point))) (and (org-in-item-p) (goto-char (org-list-top-point)))
(and (not inline-task-p) (and (not inline-task-p)
(featurep 'org-inlinetask) (featurep 'org-inlinetask)
(org-inlinetask-in-task-p))) (org-inlinetask-in-task-p))))
(not (looking-at "[ \t]*:END:"))
(not (looking-at org-drawer-regexp)))
(beginning-of-line 0)) (beginning-of-line 0))
(cond (cond
;; There was an heading above. ;; There was an heading above.
@ -18623,20 +18628,18 @@ which make use of the date at the cursor."
(setq column 0) (setq column 0)
(goto-char (match-end 0)) (goto-char (match-end 0))
(setq column (current-column)))) (setq column (current-column))))
;; A drawer had started and is unfinished: indent consequently. ;; A drawer had started and is unfinished
((looking-at org-drawer-regexp) ((looking-at org-drawer-regexp)
(goto-char (1- (match-beginning 1))) (goto-char (1- (match-beginning 1)))
(setq column (current-column))) (setq column (current-column)))
;; The drawer had ended: indent like its :END: line.
((looking-at "\\([ \t]*\\):END:")
(goto-char (match-end 1))
(setq column (current-column)))
;; Else, nothing noticeable found: get indentation and go on. ;; Else, nothing noticeable found: get indentation and go on.
(t (setq column (org-get-indentation)))))) (t (setq column (org-get-indentation))))))
;; Now apply indentation and move cursor accordingly
(goto-char pos) (goto-char pos)
(if (<= (current-column) (current-indentation)) (if (<= (current-column) (current-indentation))
(org-indent-line-to column) (org-indent-line-to column)
(save-excursion (org-indent-line-to column))) (save-excursion (org-indent-line-to column)))
;; Special polishing for properties, see `org-property-format'
(setq column (current-column)) (setq column (current-column))
(beginning-of-line 1) (beginning-of-line 1)
(if (looking-at (if (looking-at