summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2010-06-23 11:24:33 -0700
committerEric Schulte <schulte.eric@gmail.com>2010-06-23 13:41:20 -0700
commit6da29f151915fd86f40b51cbb999d3b2792aff0e (patch)
treeb933e63d0a1a39678ec473872a8594e055798a5d
parent3beba02e1ecc796c987d9a7166530de71c8a8fca (diff)
downloadorg-mode-6da29f151915fd86f40b51cbb999d3b2792aff0e.tar.gz
integrating org-babel into org.el
-rw-r--r--Makefile9
-rw-r--r--lisp/babel/ob-init.el20
-rw-r--r--lisp/babel/ob-keys.el7
-rw-r--r--lisp/babel/ob-lob.el5
-rw-r--r--lisp/babel/ob-ref.el4
-rw-r--r--lisp/babel/ob-tangle.el7
-rw-r--r--lisp/babel/ob.el76
-rw-r--r--lisp/org-exp.el1
-rw-r--r--lisp/org.el40
9 files changed, 102 insertions, 67 deletions
diff --git a/Makefile b/Makefile
index 7d7181a..c767cbd 100644
--- a/Makefile
+++ b/Makefile
@@ -30,9 +30,10 @@ infodir = $(prefix)/share/info
BATCH=$(EMACS) -batch -q -no-site-file -eval \
"(setq load-path (cons (expand-file-name\
- \"babel\"\
- (expand-file-name \"./lisp/\"))\
- (cons (expand-file-name \"./lisp/\") (cons \"$(lispdir)\" load-path))))"
+ \"langs\"\
+ (expand-file-name \"babel\" (expand-file-name \"./lisp/\")))\
+ (cons (expand-file-name \"babel\" (expand-file-name \"./lisp/\"))\
+ (cons (expand-file-name \"./lisp/\") (cons \"$(lispdir)\" load-path)))))"
# Specify the byte-compiler for compiling org-mode files
ELC= $(BATCH) -f batch-byte-compile
@@ -195,6 +196,8 @@ lisp/org-install.el: $(LISPFILES0) Makefile
--eval '(find-file "org-install.el")' \
--eval '(erase-buffer)' \
--eval '(mapc (lambda (x) (generate-file-autoloads (symbol-name x))) (quote ($(LISPFILES0))))' \
+ --eval "(insert \"(add-to-list 'load-path (expand-file-name \\\"babel\\\" (file-name-directory (or (buffer-file-name) load-file-name))))\")" \
+ --eval "(insert \"\n(add-to-list 'load-path (expand-file-name \\\"langs\\\" (expand-file-name \\\"babel\\\" (file-name-directory (or (buffer-file-name) load-file-name)))))\")\n" \
--eval '(insert "\n(provide (quote org-install))\n")' \
--eval '(save-buffer)'
mv org-install.el lisp
diff --git a/lisp/babel/ob-init.el b/lisp/babel/ob-init.el
deleted file mode 100644
index a229dea..0000000
--- a/lisp/babel/ob-init.el
+++ /dev/null
@@ -1,20 +0,0 @@
-;;; ob-init.el --- working with code blocks in org-mode
-(require 'ob)
-(require 'ob-table)
-(require 'ob-lob)
-(require 'ob-ref)
-(require 'ob-exp)
-(require 'ob-tangle)
-(require 'ob-comint)
-(require 'ob-keys)
-
-;; add the langs/ directory to the load path
-(add-to-list
- 'load-path (expand-file-name
- "langs"
- (file-name-directory (or (buffer-file-name)
- load-file-name))))
-(require 'ob-emacs-lisp)
-
-(provide 'ob-init)
-;;; ob-init.el ends here \ No newline at end of file
diff --git a/lisp/babel/ob-keys.el b/lisp/babel/ob-keys.el
index 233c4c5..b98a069 100644
--- a/lisp/babel/ob-keys.el
+++ b/lisp/babel/ob-keys.el
@@ -45,8 +45,7 @@ functions which are assigned key bindings, and see
"The keymap holding key bindings for interactive org-babel
functions.")
-(define-key org-mode-map org-babel-key-prefix org-babel-map)
-
+;;;###autoload
(defun org-babel-describe-bindings ()
"Describe all key binding placed behind the
`org-babel-key-prefix' prefix."
@@ -78,9 +77,5 @@ with keys. Each element of this list will add an entry to the
`org-babel-map' using the letter key which is the `car' of the
a-list placed behind the generic `org-babel-key-prefix'.")
-(mapc (lambda (pair)
- (define-key org-babel-map (car pair) (cdr pair)))
- org-babel-key-bindings)
-
(provide 'ob-keys)
;;; ob-keys.el ends here
diff --git a/lisp/babel/ob-lob.el b/lisp/babel/ob-lob.el
index 064c512..25eb7bd 100644
--- a/lisp/babel/ob-lob.el
+++ b/lisp/babel/ob-lob.el
@@ -31,7 +31,6 @@
;;; Code:
(require 'ob)
(require 'ob-table)
-(require 'ob-exp)
(defvar org-babel-library-of-babel nil
"Library of source-code blocks. This is an association list.
@@ -43,6 +42,7 @@ add files to this list use the `org-babel-lob-ingest' command."
:group 'org-babel
:type 'list)
+;;;###autoload
(defun org-babel-lob-ingest (&optional file)
"Add all source-blocks defined in FILE to `org-babel-library-of-babel'."
(interactive "f")
@@ -67,7 +67,7 @@ add files to this list use the `org-babel-lob-ingest' command."
"Regexp to match calls to predefined source block functions")
;; functions for executing lob one-liners
-
+;;;###autoload
(defun org-babel-lob-execute-maybe ()
"Detect if this is context for a org-babel Library Of Babel
src-block and if so then run the appropriate source block from
@@ -78,6 +78,7 @@ the Library."
(add-hook 'org-ctrl-c-ctrl-c-hook 'org-babel-lob-execute-maybe)
+;;;###autoload
(defun org-babel-lob-get-info ()
"Return the function call supplied on the current Library of
Babel line as a string.
diff --git a/lisp/babel/ob-ref.el b/lisp/babel/ob-ref.el
index c75930e..36bbcbd 100644
--- a/lisp/babel/ob-ref.el
+++ b/lisp/babel/ob-ref.el
@@ -56,6 +56,9 @@
(eval-when-compile
(require 'cl))
+(declare-function org-remove-if-not "org" (predicate seq))
+(declare-function org-at-table-p "org" (&optional table-type))
+
(defun org-babel-ref-variables (params)
"Takes a parameter alist, and return an alist of variable
names, and the emacs-lisp representation of the related value."
@@ -214,6 +217,7 @@ which case the entire range is returned."
((or (string= holder ")") (string= holder "]")) (setq depth (- depth 1)))))
(mapcar #'org-babel-trim (reverse (cons buffer return)))))
+(defvar org-bracket-link-regexp)
(defun org-babel-ref-at-ref-p ()
"Return the type of reference located at point or nil if none
of the supported reference types are found. Supported reference
diff --git a/lisp/babel/ob-tangle.el b/lisp/babel/ob-tangle.el
index 30a9623..64171b7 100644
--- a/lisp/babel/ob-tangle.el
+++ b/lisp/babel/ob-tangle.el
@@ -30,9 +30,12 @@
;;; Code:
(require 'ob)
+(require 'org-src)
(eval-when-compile
(require 'cl))
+(declare-function org-link-escape "org" (text &optional table))
+
(defcustom org-babel-tangle-w-comments nil
"Control the insertion of comments into tangled code. Non-nil
value will result in the insertion of comments for those
@@ -53,6 +56,7 @@ then the name of the language is used."
(string "Language name")
(string "File Extension"))))
+;;;###autoload
(defun org-babel-load-file (file)
"Load the contents of the Emacs Lisp source code blocks in the
org-mode formatted FILE. This function will first export the
@@ -72,6 +76,7 @@ file using `load-file'."
(load-file exported-file)
(message "loaded %s" exported-file))))
+;;;###autoload
(defun org-babel-tangle-file (file &optional target-file lang)
"Extract the bodies of all source code blocks in FILE with
`org-babel-tangle'. Optional argument TARGET-FILE can be used to
@@ -92,6 +97,7 @@ blocks by language."
"Tangle FILENAME and place the results in PUB-DIR."
(mapc (lambda (el) (copy-file el pub-dir t)) (org-babel-tangle-file filename)))
+;;;###autoload
(defun org-babel-tangle (&optional target-file lang)
"Extract the bodies of all source code blocks from the current
file into their own source-specific files. Optional argument
@@ -178,6 +184,7 @@ references."
(delete-region (save-excursion (beginning-of-line 1) (point))
(save-excursion (end-of-line 1) (forward-char 1) (point)))))
+(defvar org-stored-links)
(defun org-babel-tangle-collect-blocks (&optional lang)
"Collect all source blocks in the current org-mode file.
Return an association list of source-code block specifications of
diff --git a/lisp/babel/ob.el b/lisp/babel/ob.el
index 56eb0c8..aad0ab6 100644
--- a/lisp/babel/ob.el
+++ b/lisp/babel/ob.el
@@ -30,22 +30,35 @@
;;; Code:
(eval-when-compile (require 'cl))
-(require 'org)
(defvar org-babel-call-process-region-original)
+(declare-function show-all "outline" ())
+(declare-function tramp-compat-make-temp-file "tramp" (filename &optional dir-flag))
+(declare-function tramp-dissect-file-name "tramp" (name &optional nodefault))
+(declare-function tramp-file-name-user "tramp" (vec))
+(declare-function tramp-file-name-host "tramp" (vec))
+(declare-function org-edit-src-code "org" (context code edit-buffer-name))
+(declare-function org-open-at-point "org" (&optional in-emacs reference-buffer))
+(declare-function org-save-outline-visibility "org" (use-markers &rest body))
+(declare-function org-narrow-to-subtree "org" ())
+(declare-function org-entry-get "org" (pom property &optional inherit))
+(declare-function org-make-options-regexp "org" (kwds &optional extra))
+(declare-function org-match-string-no-properties "org" (num &optional string))
+(declare-function org-do-remove-indentation "org" (&optional n))
+(declare-function org-show-context "org" (&optional key))
+(declare-function org-at-table-p "org" (&optional table-type))
+(declare-function org-cycle "org" (&optional arg))
+(declare-function org-uniquify "org" (list))
+(declare-function org-table-import "org" (file arg))
+(declare-function org-add-hook "org-compat" (hook function &optional append local))
+(declare-function org-table-align "org-table" ())
+(declare-function org-table-end "org-table" (&optional table-type))
(declare-function orgtbl-to-generic "org-table" (table params))
+(declare-function orgtbl-to-orgtbl "org-table" (table params))
+(declare-function org-babel-lob-get-info "ob-lob" nil)
(declare-function org-babel-ref-split-args "ob-ref" (arg-string))
(declare-function org-babel-ref-variables "ob-ref" (params))
-(declare-function org-babel-lob-get-info "ob-lob" nil)
-(declare-function orgtbl-to-orgtbl "org-table" (table params))
-(declare-function org-babel-ref-resolve-reference
- "ob-ref" (ref &optional params))
-(declare-function tramp-compat-make-temp-file
- "tramp" (filename &optional dir-flag))
-(declare-function tramp-dissect-file-name
- "tramp" (name &optional nodefault))
-(declare-function tramp-file-name-user "tramp" (vec))
-(declare-function tramp-file-name-host "tramp" (vec))
+(declare-function org-babel-ref-resolve-reference "ob-ref" (ref &optional params))
(defvar org-babel-source-name-regexp
"^[ \t]*#\\+\\(srcname\\|source\\|function\\):[ \t]*"
@@ -120,6 +133,7 @@ added to the header-arguments-alist."
(org-babel-parse-inline-src-block-match)
nil))))
+;;;###autoload
(defun org-babel-execute-src-block-maybe ()
"Detect if this is context for a org-babel src-block and if so
then run `org-babel-execute-src-block'."
@@ -130,6 +144,7 @@ then run `org-babel-execute-src-block'."
(add-hook 'org-ctrl-c-ctrl-c-hook 'org-babel-execute-src-block-maybe)
+;;;###autoload
(defun org-babel-expand-src-block-maybe ()
"Detect if this is context for a org-babel src-block and if so
then run `org-babel-expand-src-block'."
@@ -139,28 +154,7 @@ then run `org-babel-expand-src-block'."
(progn (org-babel-expand-src-block current-prefix-arg info) t)
nil)))
-(defadvice org-edit-special (around org-babel-prep-session-for-edit activate)
- "Prepare the current source block's session according to it's
-header arguments before editing in an org-src buffer. This
-function is called when `org-edit-special' is called with a
-prefix argument from inside of a source-code block."
- (when current-prefix-arg
- (let* ((info (org-babel-get-src-block-info))
- (lang (nth 0 info))
- (params (nth 2 info))
- (session (cdr (assoc :session params))))
- (when (and info session) ;; we are in a source-code block with a session
- (funcall
- (intern (concat "org-babel-prep-session:" lang)) session params))))
- ad-do-it)
-
-(defadvice org-open-at-point (around org-babel-open-at-point activate)
- "If `point' is on a source code block, then open that block's
-results with `org-babel-open-src-block-results', otherwise defer
-to `org-open-at-point'."
- (interactive "P")
- (or (call-interactively #'org-babel-open-src-block-result) ad-do-it))
-
+;;;###autoload
(defun org-babel-load-in-session-maybe ()
"Detect if this is context for a org-babel src-block and if so
then run `org-babel-load-in-session'."
@@ -172,6 +166,7 @@ then run `org-babel-load-in-session'."
(add-hook 'org-metaup-hook 'org-babel-load-in-session-maybe)
+;;;###autoload
(defun org-babel-pop-to-session-maybe ()
"Detect if this is context for a org-babel src-block and if so
then run `org-babel-pop-to-session'."
@@ -230,6 +225,7 @@ can not be resolved.")
;;; functions
(defvar call-process-region)
+;;;###autoload
(defun org-babel-execute-src-block (&optional arg info params)
"Execute the current source code block, and insert the results
into the buffer. Source code execution and the collection and
@@ -303,6 +299,7 @@ arguments. This generic implementation of body expansion is
called for languages which have not defined their own specific
org-babel-expand-body:lang function." body)
+;;;###autoload
(defun org-babel-expand-src-block (&optional arg info params)
"Expand the current source code block according to it's header
arguments, and pop open the results in a preview buffer."
@@ -323,6 +320,7 @@ arguments, and pop open the results in a preview buffer."
(org-edit-src-code
nil expanded (concat "*Org-Babel Preview " (buffer-name) "[ " lang " ]*"))))
+;;;###autoload
(defun org-babel-load-in-session (&optional arg info)
"Load the body of the current source-code block. Evaluate the
header arguments for the source block before entering the
@@ -339,6 +337,7 @@ session. After loading the body this pops open the session."
(pop-to-buffer (funcall cmd session body params))
(end-of-line 1)))
+;;;###autoload
(defun org-babel-switch-to-session (&optional arg info)
"Switch to the session of the current source-code block.
If called with a prefix argument then evaluate the header arguments
@@ -370,6 +369,8 @@ of the source block to the kill ring."
(defalias 'org-babel-pop-to-session 'org-babel-switch-to-session)
+(defvar org-bracket-link-regexp)
+;;;###autoload
(defun org-babel-open-src-block-result (&optional re-run)
"If `point' is on a src block then open the results of the
source code block, otherwise return nil. With optional prefix
@@ -400,6 +401,7 @@ results already exist."
(insert (echo-res results))))))
t)))
+;;;###autoload
(defun org-babel-execute-buffer (&optional arg)
"Call `org-babel-execute-src-block' on every source block in
the current buffer."
@@ -414,6 +416,7 @@ the current buffer."
(org-babel-execute-src-block arg)
(goto-char pos-end))))))
+;;;###autoload
(defun org-babel-execute-subtree (&optional arg)
"Call `org-babel-execute-src-block' on every source block in
the current subtree."
@@ -424,6 +427,7 @@ the current subtree."
(org-babel-execute-buffer)
(widen))))
+;;;###autoload
(defun org-babel-sha1-hash (&optional info)
"Generate an sha1 hash based on the value of info."
(interactive)
@@ -504,6 +508,7 @@ portions of results lines."
(mapc 'delete-overlay org-babel-hide-result-overlays)
(setq org-babel-hide-result-overlays nil))
+;;;###autoload
(defun org-babel-hide-result-toggle-maybe ()
"Toggle visibility of result at point."
(interactive)
@@ -575,6 +580,7 @@ portions of results lines."
(unless visited-p
(kill-buffer to-be-removed))))
+(defvar org-file-properties)
(defun org-babel-params-from-properties (&optional lang)
"Return an association list of any source block params which
may be specified in the properties of the current outline entry."
@@ -612,6 +618,7 @@ may be specified at the top of the current buffer."
(org-babel-parse-header-arguments
(org-match-string-no-properties 2)))))))))
+(defvar org-src-preserve-indentation)
(defun org-babel-parse-src-block-match ()
"Parse the match data resulting from a match of the
`org-babel-src-block-regexp'."
@@ -805,6 +812,7 @@ If the point is not on a source block then return nil."
(looking-at org-babel-src-block-regexp))
(point))))))
+;;;###autoload
(defun org-babel-goto-named-source-block (&optional name)
"Go to a named source-code block."
(interactive "ssource-block name: ")
@@ -883,6 +891,7 @@ following the source block."
(if hash (org-babel-hide-hash)) t)))
(point))))))
+(defvar org-block-regexp)
(defun org-babel-read-result ()
"Read the result at `point' into emacs-lisp."
(let ((case-fold-search t) result-string)
@@ -913,6 +922,7 @@ following the source block."
(mapcar #'org-babel-read row)))
(org-table-to-lisp)))
+(defvar org-link-types-re)
(defun org-babel-read-link ()
"Read the link at `point' into emacs-lisp. If the path of the
link is a file path it is expanded using `expand-file-name'."
diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index 029e4d7..704c0b7 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -30,6 +30,7 @@
(require 'org-macs)
(require 'org-agenda)
(require 'org-exp-blocks)
+(require 'ob-exp)
(require 'org-src)
(eval-when-compile
(require 'cl))
diff --git a/lisp/org.el b/lisp/org.el
index 2628152..a721b0e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -104,6 +104,23 @@
(require 'org-src)
(require 'org-footnote)
+;; babel
+(let* ((babel-path (expand-file-name
+ "babel"
+ (file-name-directory (or (buffer-file-name)
+ load-file-name))))
+ (babel-langs-path (expand-file-name "langs" babel-path)))
+ (add-to-list 'load-path babel-path)
+ (add-to-list 'load-path babel-langs-path))
+(require 'ob)
+(require 'ob-table)
+(require 'ob-lob)
+(require 'ob-ref)
+(require 'ob-tangle)
+(require 'ob-comint)
+(require 'ob-keys)
+(require 'ob-emacs-lisp)
+
;;;; Customization variables
(defcustom org-clone-delete-id nil
"Remove ID property of clones of a subtree.
@@ -8887,6 +8904,8 @@ optional argument IN-EMACS is non-nil, Emacs will visit the file.
With a double prefix argument, try to open outside of Emacs, in the
application the system uses for this file type."
(interactive "P")
+ ;; if in a code block, then open the block's results
+ (unless (call-interactively #'org-babel-open-src-block-result)
(org-load-modules-maybe)
(move-marker org-open-link-marker (point))
(setq org-window-config-before-follow-link (current-window-configuration))
@@ -9068,7 +9087,7 @@ application the system uses for this file type."
(t
(browse-url-at-point)))))))
(move-marker org-open-link-marker nil)
- (run-hook-with-args 'org-follow-link-hook))
+ (run-hook-with-args 'org-follow-link-hook)))
(defun org-offer-links-in-entry (&optional nth zero)
"Offer links in the current entry and follow the selected link.
@@ -16010,6 +16029,12 @@ BEG and END default to the buffer boundaries."
(org-defkey org-mode-map [(control shift right)] 'org-shiftcontrolright)
(org-defkey org-mode-map [(control shift left)] 'org-shiftcontrolleft)
+;; Babel keys
+(define-key org-mode-map org-babel-key-prefix org-babel-map)
+(mapc (lambda (pair)
+ (define-key org-babel-map (car pair) (cdr pair)))
+ org-babel-key-bindings)
+
;;; Extra keys for tty access.
;; We only set them when really needed because otherwise the
;; menus don't show the simple keys
@@ -16872,14 +16897,23 @@ See the individual commands for more information."
(org-table-paste-rectangle)
(org-paste-subtree arg)))
-(defun org-edit-special ()
+(defun org-edit-special (&optional arg)
"Call a special editor for the stuff at point.
When at a table, call the formula editor with `org-table-edit-formulas'.
When at the first line of an src example, call `org-edit-src-code'.
When in an #+include line, visit the include file. Otherwise call
`ffap' to visit the file at point."
(interactive)
- (cond
+ ;; possibly prep session before editing source
+ (when arg
+ (let* ((info (org-babel-get-src-block-info))
+ (lang (nth 0 info))
+ (params (nth 2 info))
+ (session (cdr (assoc :session params))))
+ (when (and info session) ;; we are in a source-code block with a session
+ (funcall
+ (intern (concat "org-babel-prep-session:" lang)) session params))))
+ (cond ;; proceed with `org-edit-special'
((save-excursion
(beginning-of-line 1)
(looking-at "\\(?:#\\+\\(?:setupfile\\|include\\):?[ \t]+\"?\\|[ \t]*<include\\>.*?file=\"\\)\\([^\"\n>]+\\)"))