]> code.delx.au - gnu-emacs/blobdiff - lisp/org/org-src.el
* doc/emacs/dired.texi (Shell Commands in Dired): Fix typo.
[gnu-emacs] / lisp / org / org-src.el
index 5de55fa455fe61a086547ea0cc4526b6965b19c9..ac574ed4dd270d4ba695109dcc0a89e8db87ce1f 100644 (file)
@@ -1,13 +1,12 @@
 ;;; org-src.el --- Source code examples in Org
 ;;
-;; Copyright (C) 2004-201 Free Software Foundation, Inc.
+;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
 ;;
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
-;;        Bastien Guerry <bzg AT altern DOT org>
+;;        Bastien Guerry <bzg AT gnu DOT org>
 ;;         Dan Davison <davison at stats dot ox dot ac dot uk>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 7.7
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -42,6 +41,8 @@
 (declare-function org-at-table.el-p "org" ())
 (declare-function org-get-indentation "org" (&optional line))
 (declare-function org-switch-to-buffer-other-window "org" (&rest args))
+(declare-function org-pop-to-buffer-same-window
+                 "org-compat" (&optional buffer-or-name norecord label))
 
 (defcustom org-edit-src-region-extra nil
   "Additional regexps to identify regions for editing with `org-edit-src-code'.
@@ -152,7 +153,7 @@ but which mess up the display of a snippet in Org exported files.")
 (defcustom org-src-lang-modes
   '(("ocaml" . tuareg) ("elisp" . emacs-lisp) ("ditaa" . artist)
     ("asymptote" . asy) ("dot" . fundamental) ("sqlite" . sql)
-    ("calc" . fundamental) ("C" . c))
+    ("calc" . fundamental) ("C" . c) ("cpp" . c++))
   "Alist mapping languages to their major mode.
 The key is the language name, the value is the string that should
 be inserted as the name of the major mode.  For many languages this is
@@ -214,7 +215,7 @@ buffer."
        (case-fold-search t)
        (info (org-edit-src-find-region-and-lang))
        (full-info (org-babel-get-src-block-info))
-       (org-mode-p (or (org-mode-p) (derived-mode-p 'org-mode)))
+       (org-mode-p (derived-mode-p 'org-mode)) ;; derived-mode-p is reflexive
        (beg (make-marker))
        (end (make-marker))
        (allow-write-back-p (null code))
@@ -305,7 +306,7 @@ buffer."
             (error "Language mode `%s' fails with: %S" lang-f (nth 1 e)))))
        (dolist (pair transmitted-variables)
          (org-set-local (car pair) (cadr pair)))
-       (when org-mode-p
+       (when (eq major-mode 'org-mode)
          (goto-char (point-min))
          (while (re-search-forward "^," nil t)
            (if (eq (org-current-line) line) (setq total-nindent (1+ total-nindent)))
@@ -339,7 +340,7 @@ buffer."
 (defun org-src-switch-to-buffer (buffer context)
   (case org-src-window-setup
     ('current-window
-     (switch-to-buffer buffer))
+     (org-pop-to-buffer-same-window buffer))
     ('other-window
      (switch-to-buffer-other-window buffer))
     ('other-frame
@@ -350,7 +351,7 @@ buffer."
          (delete-frame frame)))
        ('save
        (kill-buffer (current-buffer))
-       (switch-to-buffer buffer))
+       (org-pop-to-buffer-same-window buffer))
        (t
        (switch-to-buffer-other-frame buffer))))
     ('reorganize-frame
@@ -362,7 +363,7 @@ buffer."
     (t
      (message "Invalid value %s for org-src-window-setup"
              (symbol-name org-src-window-setup))
-     (switch-to-buffer buffer))))
+     (org-pop-to-buffer-same-window buffer))))
 
 (defun org-src-construct-edit-buffer-name (org-buffer-name lang)
   "Construct the buffer name for a source editing buffer."
@@ -397,7 +398,7 @@ the fragment in the Org-mode buffer."
        (case-fold-search t)
        (msg (substitute-command-keys
              "Edit, then exit with C-c ' (C-c and single quote)"))
-       (org-mode-p (org-mode-p))
+       (org-mode-p (eq major-mode 'org-mode))
        (beg (make-marker))
        (end (make-marker))
        (preserve-indentation org-src-preserve-indentation)
@@ -422,7 +423,7 @@ the fragment in the Org-mode buffer."
            begline (save-excursion (goto-char beg) (org-current-line)))
       (if (and (setq buffer (org-edit-src-find-buffer beg end))
               (y-or-n-p "Return to existing edit buffer? [n] will revert changes: "))
-         (switch-to-buffer buffer)
+         (org-pop-to-buffer-same-window buffer)
        (when buffer
          (with-current-buffer buffer
            (if (boundp 'org-edit-src-overlay)
@@ -442,7 +443,7 @@ the fragment in the Org-mode buffer."
                           (define-key map [mouse-1] 'org-edit-src-continue)
                           map))
        (overlay-put ovl :read-only "Leave me alone")
-       (switch-to-buffer buffer)
+       (org-pop-to-buffer-same-window buffer)
        (insert code)
        (remove-text-properties (point-min) (point-max)
                                '(display nil invisible nil intangible nil))
@@ -616,7 +617,7 @@ the language, a switch telling if the content should be in a single line."
       (when (org-bound-and-true-p org-edit-src-from-org-mode)
        (goto-char (point-min))
        (while (re-search-forward
-               (if (org-mode-p) "^\\(.\\)" "^\\([*]\\|[ \t]*#\\+\\)") nil t)
+               (if (eq major-mode 'org-mode) "^\\(.\\)" "^\\([*]\\|[ \t]*#\\+\\)") nil t)
          (if (eq (org-current-line) line) (setq delta (1+ delta)))
          (replace-match ",\\1")))
       (when (org-bound-and-true-p org-edit-src-picture)
@@ -715,6 +716,7 @@ the language, a switch telling if the content should be in a single line."
         (with-current-buffer (marker-buffer beg-marker)
           (goto-char (marker-position beg-marker))
           ,@body))))
+(def-edebug-spec org-src-do-at-code-block (body))
 
 (defun org-src-do-key-sequence-at-code-block (&optional key)
   "Execute key sequence at code block in the source Org buffer.
@@ -811,5 +813,4 @@ LANG is a string, and the returned major mode is a symbol."
 
 (provide 'org-src)
 
-
 ;;; org-src.el ends here