2015-10-26 00:56:00 +00:00
|
|
|
|
;;; org-src.el --- Source code examples in Org -*- lexical-binding: t; -*-
|
2009-06-07 14:27:07 +00:00
|
|
|
|
;;
|
2024-01-02 01:47:10 +00:00
|
|
|
|
;; Copyright (C) 2004-2024 Free Software Foundation, Inc.
|
2009-06-07 14:27:07 +00:00
|
|
|
|
;;
|
2021-05-07 14:50:57 +00:00
|
|
|
|
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
|
2013-10-08 06:07:21 +00:00
|
|
|
|
;; Bastien Guerry <bzg@gnu.org>
|
2009-10-27 18:11:09 +00:00
|
|
|
|
;; Dan Davison <davison at stats dot ox dot ac dot uk>
|
2009-06-07 14:27:07 +00:00
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
2021-09-26 07:44:29 +00:00
|
|
|
|
;; URL: https://orgmode.org
|
2009-06-07 14:27:07 +00:00
|
|
|
|
;;
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
;;
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 22:52:52 +00:00
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2009-06-07 14:27:07 +00:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;;
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
2016-07-25 14:01:15 +00:00
|
|
|
|
;; This file contains the code dealing with source code examples in
|
|
|
|
|
;; Org mode.
|
2009-06-07 14:27:07 +00:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2022-08-04 13:53:05 +00:00
|
|
|
|
(require 'org-macs)
|
|
|
|
|
(org-assert-version)
|
|
|
|
|
|
2016-07-25 14:01:15 +00:00
|
|
|
|
(require 'cl-lib)
|
2018-07-02 14:06:38 +00:00
|
|
|
|
(require 'ob-comint)
|
2009-06-07 14:27:07 +00:00
|
|
|
|
(require 'org-macs)
|
|
|
|
|
(require 'org-compat)
|
2018-07-02 14:06:38 +00:00
|
|
|
|
(require 'org-keys)
|
2023-04-17 14:57:35 +00:00
|
|
|
|
(require 'sh-script)
|
2009-06-07 14:27:07 +00:00
|
|
|
|
|
2021-09-30 20:07:15 +00:00
|
|
|
|
(declare-function org--get-expected-indentation "org" (element contentsp))
|
2020-12-13 18:56:29 +00:00
|
|
|
|
(declare-function org-mode "org" ())
|
2021-10-01 01:27:41 +00:00
|
|
|
|
(declare-function org--get-expected-indentation "org" (element contentsp))
|
2022-10-09 03:42:59 +00:00
|
|
|
|
(declare-function org-fold-region "org-fold" (from to flag &optional spec-or-alias))
|
2022-01-06 17:39:05 +00:00
|
|
|
|
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
|
2016-10-25 11:23:31 +00:00
|
|
|
|
(declare-function org-element-class "org-element" (datum &optional parent))
|
2015-05-30 12:28:35 +00:00
|
|
|
|
(declare-function org-element-context "org-element" (&optional element))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(declare-function org-element-lineage "org-element-ast"
|
2015-05-30 12:28:35 +00:00
|
|
|
|
(blob &optional types with-self))
|
2021-12-06 02:48:10 +00:00
|
|
|
|
(declare-function org-element--parse-paired-brackets "org-element" (char))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(declare-function org-element-property "org-element-ast" (property node))
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(declare-function org-element-begin "org-element" (node))
|
|
|
|
|
(declare-function org-element-end "org-element" (node))
|
|
|
|
|
(declare-function org-element-contents-begin "org-element" (node))
|
|
|
|
|
(declare-function org-element-contents-end "org-element" (node))
|
|
|
|
|
(declare-function org-element-post-affiliated "org-element" (node))
|
|
|
|
|
(declare-function org-element-post-blank "org-element" (node))
|
|
|
|
|
(declare-function org-element-parent "org-element-ast" (node))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(declare-function org-element-type "org-element-ast" (node &optional anonymous))
|
|
|
|
|
(declare-function org-element-type-p "org-element-ast" (node types))
|
2015-05-30 12:28:35 +00:00
|
|
|
|
(declare-function org-footnote-goto-definition "org-footnote"
|
|
|
|
|
(label &optional location))
|
|
|
|
|
|
2015-10-26 08:29:13 +00:00
|
|
|
|
(defvar org-inhibit-startup)
|
2009-06-07 15:07:07 +00:00
|
|
|
|
|
2013-04-16 08:38:01 +00:00
|
|
|
|
(defcustom org-edit-src-turn-on-auto-save nil
|
|
|
|
|
"Non-nil means turn `auto-save-mode' on when editing a source block.
|
|
|
|
|
This will save the content of the source code editing buffer into
|
|
|
|
|
a newly created file, not the base buffer for this source block.
|
|
|
|
|
|
2013-11-17 08:12:41 +00:00
|
|
|
|
If you want to regularly save the base buffer instead of the source
|
2013-04-16 08:38:01 +00:00
|
|
|
|
code editing buffer, see `org-edit-src-auto-save-idle-delay' instead."
|
|
|
|
|
:group 'org-edit-structure
|
|
|
|
|
:version "24.4"
|
|
|
|
|
:package-version '(Org . "8.0")
|
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
2013-03-02 14:04:43 +00:00
|
|
|
|
(defcustom org-edit-src-auto-save-idle-delay 0
|
2013-04-16 08:38:01 +00:00
|
|
|
|
"Delay before saving a source code buffer back into its base buffer.
|
2013-02-16 10:35:39 +00:00
|
|
|
|
When a positive integer N, save after N seconds of idle time.
|
2013-04-16 08:38:01 +00:00
|
|
|
|
When 0 (the default), don't auto-save.
|
|
|
|
|
|
|
|
|
|
If you want to save the source code buffer itself, don't use this.
|
|
|
|
|
Check `org-edit-src-turn-on-auto-save' instead."
|
2013-02-16 10:35:39 +00:00
|
|
|
|
:group 'org-edit-structure
|
2013-02-26 17:21:28 +00:00
|
|
|
|
:version "24.4"
|
|
|
|
|
:package-version '(Org . "8.0")
|
2013-02-16 10:35:39 +00:00
|
|
|
|
:type 'integer)
|
|
|
|
|
|
2009-06-07 14:27:07 +00:00
|
|
|
|
(defcustom org-coderef-label-format "(ref:%s)"
|
|
|
|
|
"The default coderef format.
|
|
|
|
|
This format string will be used to search for coderef labels in literal
|
2009-07-23 19:48:43 +00:00
|
|
|
|
examples (EXAMPLE and SRC blocks). The format can be overwritten in
|
2010-05-01 02:53:53 +00:00
|
|
|
|
an individual literal example with the -l option, like
|
2009-06-07 14:27:07 +00:00
|
|
|
|
|
|
|
|
|
#+BEGIN_SRC pascal +n -r -l \"((%s))\"
|
|
|
|
|
...
|
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
|
|
If you want to use this for HTML export, make sure that the format does
|
|
|
|
|
not introduce special font-locking, and avoid the HTML special
|
|
|
|
|
characters `<', `>', and `&'. The reason for this restriction is that
|
|
|
|
|
the labels are searched for only after htmlize has done its job."
|
|
|
|
|
:group 'org-edit-structure ; FIXME this is not in the right group
|
|
|
|
|
:type 'string)
|
|
|
|
|
|
|
|
|
|
(defcustom org-edit-fixed-width-region-mode 'artist-mode
|
|
|
|
|
"The mode that should be used to edit fixed-width regions.
|
|
|
|
|
These are the regions where each line starts with a colon."
|
|
|
|
|
:group 'org-edit-structure
|
|
|
|
|
:type '(choice
|
|
|
|
|
(const artist-mode)
|
|
|
|
|
(const picture-mode)
|
|
|
|
|
(const fundamental-mode)
|
|
|
|
|
(function :tag "Other (specify)")))
|
|
|
|
|
|
2009-10-08 03:49:37 +00:00
|
|
|
|
(defcustom org-src-preserve-indentation nil
|
2010-07-17 18:53:36 +00:00
|
|
|
|
"If non-nil preserve leading whitespace characters on export.
|
2024-01-29 10:12:18 +00:00
|
|
|
|
|
|
|
|
|
If non-nil leading whitespace characters in source code blocks are
|
|
|
|
|
preserved on export, or adjusted while indenting or when switching
|
|
|
|
|
between the org buffer and the language mode edit buffer.
|
|
|
|
|
|
|
|
|
|
When this variable is nil, while indenting with `\\[org-indent-block]'
|
|
|
|
|
or after editing with `\\[org-edit-src-code]', the minimum (across-lines)
|
|
|
|
|
number of leading whitespace characters are removed from all lines,
|
|
|
|
|
and the code block is uniformly indented according to the value of
|
|
|
|
|
`org-edit-src-content-indentation'."
|
2009-10-08 03:49:37 +00:00
|
|
|
|
:group 'org-edit-structure
|
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
2009-06-08 07:39:19 +00:00
|
|
|
|
(defcustom org-edit-src-content-indentation 2
|
2009-10-08 03:56:37 +00:00
|
|
|
|
"Indentation for the content of a source code block.
|
2016-10-15 15:36:47 +00:00
|
|
|
|
|
2009-06-08 07:39:19 +00:00
|
|
|
|
This should be the number of spaces added to the indentation of the #+begin
|
|
|
|
|
line in order to compute the indentation of the block content after
|
2016-10-15 15:36:47 +00:00
|
|
|
|
editing it with `\\[org-edit-src-code]'.
|
|
|
|
|
|
|
|
|
|
It has no effect if `org-src-preserve-indentation' is non-nil."
|
2009-06-08 07:39:19 +00:00
|
|
|
|
:group 'org-edit-structure
|
2017-12-17 10:01:25 +00:00
|
|
|
|
:type 'integer
|
|
|
|
|
:safe #'wholenump)
|
2009-06-08 07:39:19 +00:00
|
|
|
|
|
2009-06-07 14:27:07 +00:00
|
|
|
|
(defcustom org-edit-src-persistent-message t
|
|
|
|
|
"Non-nil means show persistent exit help message while editing src examples.
|
|
|
|
|
The message is shown in the header-line, which will be created in the
|
2011-02-01 11:42:28 +00:00
|
|
|
|
first line of the window showing the editing buffer."
|
2009-06-07 14:27:07 +00:00
|
|
|
|
:group 'org-edit-structure
|
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
2014-11-23 22:34:47 +00:00
|
|
|
|
(defcustom org-src-ask-before-returning-to-edit-buffer t
|
|
|
|
|
"Non-nil means ask before switching to an existing edit buffer.
|
|
|
|
|
If nil, when `org-edit-src-code' is used on a block that already
|
|
|
|
|
has an active edit buffer, it will switch to that edit buffer
|
|
|
|
|
immediately; otherwise it will ask whether you want to return to
|
|
|
|
|
the existing edit buffer."
|
|
|
|
|
:group 'org-edit-structure
|
|
|
|
|
:version "24.4"
|
|
|
|
|
:package-version '(Org . "8.0")
|
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
2009-10-27 18:11:09 +00:00
|
|
|
|
(defcustom org-src-window-setup 'reorganize-frame
|
|
|
|
|
"How the source code edit buffer should be displayed.
|
|
|
|
|
Possible values for this option are:
|
|
|
|
|
|
2020-01-19 16:28:36 +00:00
|
|
|
|
plain Show edit buffer using `display-buffer'. Users can
|
|
|
|
|
further control the display behavior by modifying
|
|
|
|
|
`display-buffer-alist' and its relatives.
|
2018-03-12 17:23:52 +00:00
|
|
|
|
current-window Show edit buffer in the current window, keeping all other
|
|
|
|
|
windows.
|
|
|
|
|
split-window-below Show edit buffer below the current window, keeping all
|
|
|
|
|
other windows.
|
2019-07-11 09:24:15 +00:00
|
|
|
|
split-window-right Show edit buffer to the right of the current window,
|
|
|
|
|
keeping all other windows.
|
2018-03-12 17:23:52 +00:00
|
|
|
|
other-window Use `switch-to-buffer-other-window' to display edit buffer.
|
|
|
|
|
reorganize-frame Show only two windows on the current frame, the current
|
2019-12-23 16:55:55 +00:00
|
|
|
|
window and the edit buffer.
|
2018-03-12 17:23:52 +00:00
|
|
|
|
other-frame Use `switch-to-buffer-other-frame' to display edit buffer.
|
2019-12-23 16:55:55 +00:00
|
|
|
|
Also, when exiting the edit buffer, kill that frame.
|
|
|
|
|
|
|
|
|
|
Values that modify the window layout (reorganize-frame, split-window-below,
|
|
|
|
|
split-window-right) will restore the layout after exiting the edit buffer."
|
2009-10-27 18:11:09 +00:00
|
|
|
|
:group 'org-edit-structure
|
|
|
|
|
:type '(choice
|
2022-07-08 15:56:55 +00:00
|
|
|
|
(const plain)
|
2009-10-27 18:11:09 +00:00
|
|
|
|
(const current-window)
|
2018-03-12 17:23:52 +00:00
|
|
|
|
(const split-window-below)
|
2019-07-11 09:24:15 +00:00
|
|
|
|
(const split-window-right)
|
2009-10-27 18:11:09 +00:00
|
|
|
|
(const other-frame)
|
|
|
|
|
(const other-window)
|
|
|
|
|
(const reorganize-frame)))
|
|
|
|
|
|
2009-06-08 06:52:25 +00:00
|
|
|
|
(defvar org-src-mode-hook nil
|
2015-05-01 08:03:17 +00:00
|
|
|
|
"Hook run after Org switched a source code snippet to its Emacs mode.
|
2015-05-01 07:49:14 +00:00
|
|
|
|
\\<org-mode-map>
|
|
|
|
|
This hook will run:
|
2016-10-15 15:36:47 +00:00
|
|
|
|
- when editing a source code snippet with `\\[org-edit-special]'
|
2015-05-01 07:49:14 +00:00
|
|
|
|
- when formatting a source code snippet for export with htmlize.
|
2009-06-08 06:52:25 +00:00
|
|
|
|
|
|
|
|
|
You may want to use this hook for example to turn off `outline-minor-mode'
|
|
|
|
|
or similar things which you want to have when editing a source code file,
|
|
|
|
|
but which mess up the display of a snippet in Org exported files.")
|
|
|
|
|
|
2023-04-17 14:57:35 +00:00
|
|
|
|
(defun org-src--get-known-shells ()
|
|
|
|
|
"List all the shells in `sh-ancestor-alist' for `org-src-lang-modes'.
|
|
|
|
|
The shells are associated with `sh-mode'."
|
|
|
|
|
(mapcar
|
|
|
|
|
(lambda (shell) (cons (symbol-name shell) 'sh))
|
2023-07-05 15:50:44 +00:00
|
|
|
|
(delete-dups (org--flatten-tree sh-ancestor-alist))))
|
2023-04-17 14:57:35 +00:00
|
|
|
|
|
2009-08-23 17:31:47 +00:00
|
|
|
|
(defcustom org-src-lang-modes
|
2023-04-17 14:57:35 +00:00
|
|
|
|
`(("C" . c)
|
2018-05-01 21:16:02 +00:00
|
|
|
|
("C++" . c++)
|
|
|
|
|
("asymptote" . asy)
|
|
|
|
|
("beamer" . latex)
|
|
|
|
|
("calc" . fundamental)
|
|
|
|
|
("cpp" . c++)
|
|
|
|
|
("ditaa" . artist)
|
2022-04-02 16:36:21 +00:00
|
|
|
|
("desktop" . conf-desktop)
|
2018-05-01 21:16:02 +00:00
|
|
|
|
("dot" . fundamental)
|
|
|
|
|
("elisp" . emacs-lisp)
|
|
|
|
|
("ocaml" . tuareg)
|
|
|
|
|
("screen" . shell-script)
|
2022-04-02 16:36:21 +00:00
|
|
|
|
("sqlite" . sql)
|
2023-04-17 14:57:35 +00:00
|
|
|
|
("toml" . conf-toml)
|
|
|
|
|
("shell" . sh)
|
|
|
|
|
,@(org-src--get-known-shells))
|
2009-08-23 17:31:47 +00:00
|
|
|
|
"Alist mapping languages to their major mode.
|
2018-05-01 21:16:02 +00:00
|
|
|
|
|
|
|
|
|
The key is the language name. The value is the mode name, as
|
|
|
|
|
a string or a symbol, without the \"-mode\" suffix.
|
|
|
|
|
|
|
|
|
|
For many languages this is simple, but for language where this is
|
|
|
|
|
not the case, this variable provides a way to simplify things on
|
|
|
|
|
the user side. For example, there is no `ocaml-mode' in Emacs,
|
|
|
|
|
but the mode to use is `tuareg-mode'."
|
2009-08-23 17:31:47 +00:00
|
|
|
|
:group 'org-edit-structure
|
2023-04-17 14:57:35 +00:00
|
|
|
|
:package-version '(Org . "9.7")
|
2009-08-23 17:31:47 +00:00
|
|
|
|
:type '(repeat
|
|
|
|
|
(cons
|
|
|
|
|
(string "Language name")
|
|
|
|
|
(symbol "Major mode"))))
|
|
|
|
|
|
2016-09-24 08:52:49 +00:00
|
|
|
|
(defcustom org-src-block-faces nil
|
|
|
|
|
"Alist of faces to be used for source-block.
|
|
|
|
|
Each element is a cell of the format
|
|
|
|
|
|
|
|
|
|
(\"language\" FACE)
|
|
|
|
|
|
2023-02-17 12:17:04 +00:00
|
|
|
|
Where FACE is either a defined face or an anonymous face. Empty
|
|
|
|
|
language string refers to source blocks without specified language.
|
2016-09-24 08:52:49 +00:00
|
|
|
|
|
2022-07-25 19:54:49 +00:00
|
|
|
|
For instance, the following would color the background of
|
2016-09-24 08:52:49 +00:00
|
|
|
|
emacs-lisp source blocks and python source blocks in purple and
|
|
|
|
|
green, respectability.
|
|
|
|
|
|
2022-07-25 19:54:49 +00:00
|
|
|
|
(setq org-src-block-faces
|
|
|
|
|
\\='((\"emacs-lisp\" (:background \"#EEE2FF\"))
|
|
|
|
|
(\"python\" (:background \"#e5ffb8\"))))"
|
2016-09-24 08:52:49 +00:00
|
|
|
|
:group 'org-edit-structure
|
|
|
|
|
:type '(repeat (list (string :tag "language")
|
|
|
|
|
(choice
|
|
|
|
|
(face :tag "Face")
|
|
|
|
|
(sexp :tag "Anonymous face"))))
|
|
|
|
|
:package-version '(Org . "9.0"))
|
|
|
|
|
|
2020-02-21 15:35:56 +00:00
|
|
|
|
(defcustom org-src-tab-acts-natively t
|
2021-09-30 20:07:15 +00:00
|
|
|
|
"If non-nil, TAB uses the language's major-mode binding in code blocks."
|
2014-11-11 16:31:40 +00:00
|
|
|
|
:type 'boolean
|
2020-05-06 00:10:15 +00:00
|
|
|
|
:package-version '(Org . "9.4")
|
2014-11-11 16:31:40 +00:00
|
|
|
|
:group 'org-babel)
|
|
|
|
|
|
2010-08-17 21:45:47 +00:00
|
|
|
|
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
|
|
|
|
;;; Internal functions and variables
|
2009-06-07 14:27:07 +00:00
|
|
|
|
|
2018-07-01 22:45:12 +00:00
|
|
|
|
(defvar org-src--auto-save-timer nil
|
|
|
|
|
"Idle Timer auto-saving remote editing buffers.")
|
|
|
|
|
|
2018-05-02 21:52:35 +00:00
|
|
|
|
(defvar-local org-src--allow-write-back t)
|
|
|
|
|
(put 'org-src--allow-write-back 'permanent-local t)
|
|
|
|
|
|
|
|
|
|
(defvar-local org-src--babel-info nil)
|
|
|
|
|
(put 'org-src--babel-info 'permanent-local t)
|
|
|
|
|
|
|
|
|
|
(defvar-local org-src--beg-marker nil)
|
|
|
|
|
(put 'org-src--beg-marker 'permanent-local t)
|
|
|
|
|
|
|
|
|
|
(defvar-local org-src--block-indentation nil)
|
|
|
|
|
(put 'org-src--block-indentation 'permanent-local t)
|
|
|
|
|
|
2019-10-09 01:00:50 +00:00
|
|
|
|
(defvar-local org-src--content-indentation nil)
|
|
|
|
|
(put 'org-src--content-indentation 'permanent-local t)
|
|
|
|
|
|
2018-05-02 21:52:35 +00:00
|
|
|
|
(defvar-local org-src--end-marker nil)
|
|
|
|
|
(put 'org-src--end-marker 'permanent-local t)
|
|
|
|
|
|
|
|
|
|
(defvar-local org-src--from-org-mode nil)
|
|
|
|
|
(put 'org-src--from-org-mode 'permanent-local t)
|
|
|
|
|
|
|
|
|
|
(defvar-local org-src--overlay nil)
|
|
|
|
|
(put 'org-src--overlay 'permanent-local t)
|
|
|
|
|
|
|
|
|
|
(defvar-local org-src--preserve-indentation nil)
|
|
|
|
|
(put 'org-src--preserve-indentation 'permanent-local t)
|
|
|
|
|
|
|
|
|
|
(defvar-local org-src--remote nil)
|
|
|
|
|
(put 'org-src--remote 'permanent-local t)
|
|
|
|
|
|
2019-12-23 16:55:55 +00:00
|
|
|
|
(defvar-local org-src--saved-temp-window-config nil)
|
|
|
|
|
(put 'org-src--saved-temp-window-config 'permanent-local t)
|
|
|
|
|
|
2018-05-02 21:52:35 +00:00
|
|
|
|
(defvar-local org-src--source-type nil
|
2017-04-29 09:45:45 +00:00
|
|
|
|
"Type of element being edited, as a symbol.")
|
2018-05-02 21:52:35 +00:00
|
|
|
|
(put 'org-src--source-type 'permanent-local t)
|
|
|
|
|
|
|
|
|
|
(defvar-local org-src--tab-width nil
|
2017-04-29 09:45:45 +00:00
|
|
|
|
"Contains `tab-width' value from Org source buffer.
|
|
|
|
|
However, if `indent-tabs-mode' is nil in that buffer, its value
|
|
|
|
|
is 0.")
|
2018-05-02 21:52:35 +00:00
|
|
|
|
(put 'org-src--tab-width 'permanent-local t)
|
2014-11-11 16:31:40 +00:00
|
|
|
|
|
2018-11-04 15:37:59 +00:00
|
|
|
|
(defvar-local org-src-source-file-name nil
|
|
|
|
|
"File name associated to Org source buffer, or nil.")
|
|
|
|
|
(put 'org-src-source-file-name 'permanent-local t)
|
|
|
|
|
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(defun org-src--construct-edit-buffer-name (org-buffer-name lang)
|
2021-09-30 20:07:15 +00:00
|
|
|
|
"Construct the buffer name for a source editing buffer.
|
2023-03-10 11:08:44 +00:00
|
|
|
|
Format is \"*Org Src ORG-BUFFER-NAME[ LANG ]*\"."
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(concat "*Org Src " org-buffer-name "[ " lang " ]*"))
|
2009-10-14 22:43:25 +00:00
|
|
|
|
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(defun org-src--edit-buffer (beg end)
|
|
|
|
|
"Return buffer editing area between BEG and END.
|
|
|
|
|
Return nil if there is no such buffer."
|
|
|
|
|
(catch 'exit
|
|
|
|
|
(dolist (b (buffer-list))
|
|
|
|
|
(with-current-buffer b
|
|
|
|
|
(and (org-src-edit-buffer-p)
|
2014-12-12 04:34:35 +00:00
|
|
|
|
(= beg org-src--beg-marker)
|
|
|
|
|
(eq (marker-buffer beg) (marker-buffer org-src--beg-marker))
|
|
|
|
|
(= end org-src--end-marker)
|
|
|
|
|
(eq (marker-buffer end) (marker-buffer org-src--end-marker))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(throw 'exit b))))))
|
|
|
|
|
|
|
|
|
|
(defun org-src--coordinates (pos beg end)
|
|
|
|
|
"Return coordinates of POS relatively to BEG and END.
|
|
|
|
|
POS, BEG and END are buffer positions. Return value is either
|
|
|
|
|
a cons cell (LINE . COLUMN) or symbol `end'. See also
|
|
|
|
|
`org-src--goto-coordinates'."
|
|
|
|
|
(if (>= pos end) 'end
|
|
|
|
|
(org-with-wide-buffer
|
|
|
|
|
(goto-char (max beg pos))
|
2021-08-30 21:18:41 +00:00
|
|
|
|
(cons (count-lines (save-excursion (goto-char beg) (line-beginning-position))
|
|
|
|
|
(line-beginning-position))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
;; Column is relative to the end of line to avoid problems of
|
|
|
|
|
;; comma escaping or colons appended in front of the line.
|
2021-04-28 10:17:00 +00:00
|
|
|
|
(- (point) (min end (line-end-position)))))))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
|
|
|
|
(defun org-src--goto-coordinates (coord beg end)
|
|
|
|
|
"Move to coordinates COORD relatively to BEG and END.
|
|
|
|
|
COORD are coordinates, as returned by `org-src--coordinates',
|
|
|
|
|
which see. BEG and END are buffer positions."
|
|
|
|
|
(goto-char
|
|
|
|
|
(if (eq coord 'end) (max (1- end) beg)
|
|
|
|
|
;; If BEG happens to be located outside of the narrowed part of
|
|
|
|
|
;; the buffer, widen it first.
|
|
|
|
|
(org-with-wide-buffer
|
|
|
|
|
(goto-char beg)
|
|
|
|
|
(forward-line (car coord))
|
2021-04-28 10:17:00 +00:00
|
|
|
|
(max (point)
|
|
|
|
|
(+ (min end (line-end-position))
|
|
|
|
|
(cdr coord)))))))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(defun org-src--contents-area (datum)
|
|
|
|
|
"Return contents boundaries of DATUM.
|
2015-05-22 18:59:31 +00:00
|
|
|
|
DATUM is an element or object. Return a list (BEG END CONTENTS)
|
|
|
|
|
where BEG and END are buffer positions and CONTENTS is a string."
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(let ((type (org-element-type datum)))
|
2015-08-13 22:17:47 +00:00
|
|
|
|
(org-with-wide-buffer
|
|
|
|
|
(cond
|
|
|
|
|
((eq type 'footnote-definition)
|
|
|
|
|
(let* ((beg (progn
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(goto-char (org-element-post-affiliated datum))
|
2015-08-13 22:17:47 +00:00
|
|
|
|
(search-forward "]")))
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(end (or (org-element-contents-end datum) beg)))
|
2015-08-13 22:17:47 +00:00
|
|
|
|
(list beg end (buffer-substring-no-properties beg end))))
|
2015-11-08 19:55:31 +00:00
|
|
|
|
((eq type 'inline-src-block)
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(let ((beg (progn (goto-char (org-element-begin datum))
|
2015-11-08 19:55:31 +00:00
|
|
|
|
(search-forward "{" (line-end-position) t)))
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(end (progn (goto-char (org-element-end datum))
|
2015-11-08 19:55:31 +00:00
|
|
|
|
(search-backward "}" (line-beginning-position) t))))
|
|
|
|
|
(list beg end (buffer-substring-no-properties beg end))))
|
2020-05-24 15:35:33 +00:00
|
|
|
|
((eq type 'latex-fragment)
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(let ((beg (org-element-begin datum))
|
|
|
|
|
(end (org-with-point-at (org-element-end datum)
|
2020-05-24 15:35:33 +00:00
|
|
|
|
(skip-chars-backward " \t")
|
|
|
|
|
(point))))
|
|
|
|
|
(list beg end (buffer-substring-no-properties beg end))))
|
2023-05-03 14:26:41 +00:00
|
|
|
|
((org-element-contents-begin datum)
|
|
|
|
|
(let ((beg (org-element-contents-begin datum))
|
|
|
|
|
(end (org-element-contents-end datum)))
|
2015-08-13 22:17:47 +00:00
|
|
|
|
(list beg end (buffer-substring-no-properties beg end))))
|
2022-07-30 05:24:10 +00:00
|
|
|
|
((memq type '(example-block export-block src-block comment-block))
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(list (progn (goto-char (org-element-post-affiliated datum))
|
2015-08-13 22:17:47 +00:00
|
|
|
|
(line-beginning-position 2))
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(progn (goto-char (org-element-end datum))
|
2015-08-13 22:17:47 +00:00
|
|
|
|
(skip-chars-backward " \r\t\n")
|
|
|
|
|
(line-beginning-position 1))
|
|
|
|
|
(org-element-property :value datum)))
|
2017-02-01 20:30:54 +00:00
|
|
|
|
((memq type '(fixed-width latex-environment table))
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(let ((beg (org-element-post-affiliated datum))
|
|
|
|
|
(end (progn (goto-char (org-element-end datum))
|
2015-08-13 22:17:47 +00:00
|
|
|
|
(skip-chars-backward " \r\t\n")
|
|
|
|
|
(line-beginning-position 2))))
|
|
|
|
|
(list beg
|
|
|
|
|
end
|
|
|
|
|
(if (eq type 'fixed-width) (org-element-property :value datum)
|
|
|
|
|
(buffer-substring-no-properties beg end)))))
|
|
|
|
|
(t (error "Unsupported element or object: %s" type))))))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
|
|
|
|
(defun org-src--make-source-overlay (beg end edit-buffer)
|
|
|
|
|
"Create overlay between BEG and END positions and return it.
|
|
|
|
|
EDIT-BUFFER is the buffer currently editing area between BEG and
|
|
|
|
|
END."
|
|
|
|
|
(let ((overlay (make-overlay beg end)))
|
|
|
|
|
(overlay-put overlay 'face 'secondary-selection)
|
|
|
|
|
(overlay-put overlay 'edit-buffer edit-buffer)
|
|
|
|
|
(overlay-put overlay 'help-echo
|
|
|
|
|
"Click with mouse-1 to switch to buffer editing this segment")
|
|
|
|
|
(overlay-put overlay 'face 'secondary-selection)
|
|
|
|
|
(overlay-put overlay 'keymap
|
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
|
(define-key map [mouse-1] 'org-edit-src-continue)
|
|
|
|
|
map))
|
2015-05-01 19:14:19 +00:00
|
|
|
|
(let ((read-only
|
|
|
|
|
(list
|
|
|
|
|
(lambda (&rest _)
|
|
|
|
|
(user-error
|
|
|
|
|
"Cannot modify an area being edited in a dedicated buffer")))))
|
|
|
|
|
(overlay-put overlay 'modification-hooks read-only)
|
|
|
|
|
(overlay-put overlay 'insert-in-front-hooks read-only)
|
|
|
|
|
(overlay-put overlay 'insert-behind-hooks read-only))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
overlay))
|
|
|
|
|
|
2015-02-18 01:05:57 +00:00
|
|
|
|
(defun org-src--remove-overlay ()
|
|
|
|
|
"Remove overlay from current source buffer."
|
|
|
|
|
(when (overlayp org-src--overlay) (delete-overlay org-src--overlay)))
|
|
|
|
|
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(defun org-src--on-datum-p (datum)
|
|
|
|
|
"Non-nil when point is on DATUM.
|
|
|
|
|
DATUM is an element or an object. Consider blank lines or white
|
|
|
|
|
spaces after it as being outside."
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(and (>= (point) (org-element-begin datum))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(<= (point)
|
2023-07-13 08:51:15 +00:00
|
|
|
|
(org-with-wide-buffer
|
|
|
|
|
(goto-char (org-element-end datum))
|
|
|
|
|
(skip-chars-backward " \r\t\n")
|
|
|
|
|
(if (eq (org-element-class datum) 'element)
|
|
|
|
|
(line-end-position)
|
|
|
|
|
(point))))))
|
|
|
|
|
|
|
|
|
|
(defun org-src-preserve-indentation-p (&optional node)
|
|
|
|
|
"Non-nil when indentation should be preserved within NODE.
|
|
|
|
|
When NODE is not passed, assume element at point."
|
|
|
|
|
(let ((node (or node (org-element-at-point))))
|
|
|
|
|
(and (org-element-type-p node '(example-block src-block))
|
|
|
|
|
(or (org-element-property :preserve-indent node)
|
|
|
|
|
org-src-preserve-indentation))))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
2023-07-13 09:28:13 +00:00
|
|
|
|
(defun org-src--contents-for-write-back-1
|
|
|
|
|
( write-back-buf contents
|
|
|
|
|
&optional indentation-offset preserve-fl source-tab-width write-back)
|
|
|
|
|
"Populate WRITE-BACK-BUF with CONTENTS in the appropriate format.
|
|
|
|
|
|
|
|
|
|
INDENTATION-OFFSET, when non-nil is additional indentation to be applied
|
|
|
|
|
to all the lines. PRESERVE-FL means that first line should not be
|
|
|
|
|
indented (useful for inline blocks contents that belong to paragraph).
|
|
|
|
|
The original indentation, if any, is not altered.
|
|
|
|
|
|
|
|
|
|
TAB-WIDTH is `tab-width' to be used when indenting. The value of 0
|
|
|
|
|
means that tabs should not be used.
|
|
|
|
|
|
|
|
|
|
WRITE-BACK, when non-nil, is a function to be called with point at
|
|
|
|
|
WRITE-BACK-BUF after inserting the original contents, but before
|
|
|
|
|
applying extra indentation."
|
|
|
|
|
(let ((use-tabs? (and (> source-tab-width 0) t))
|
|
|
|
|
indent-str)
|
2020-10-04 19:33:30 +00:00
|
|
|
|
(with-current-buffer write-back-buf
|
2017-04-29 09:45:45 +00:00
|
|
|
|
;; Apply WRITE-BACK function on edit buffer contents.
|
2023-07-13 09:28:13 +00:00
|
|
|
|
(insert (org-no-properties contents))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(goto-char (point-min))
|
2017-04-29 09:45:45 +00:00
|
|
|
|
(when (functionp write-back) (save-excursion (funcall write-back)))
|
2021-05-18 12:39:33 +00:00
|
|
|
|
;; Add INDENTATION-OFFSET to every line in buffer,
|
2017-04-29 09:45:45 +00:00
|
|
|
|
;; unless indentation is meant to be preserved.
|
2023-07-13 09:28:13 +00:00
|
|
|
|
(when (and indentation-offset (> indentation-offset 0))
|
|
|
|
|
;; The exact sequence of tabs and spaces used to indent
|
|
|
|
|
;; up to `indentation-offset' in the Org buffer.
|
|
|
|
|
(setq indent-str
|
|
|
|
|
(with-temp-buffer
|
|
|
|
|
;; Reproduce indentation parameters.
|
|
|
|
|
(setq indent-tabs-mode use-tabs?)
|
|
|
|
|
(when (> source-tab-width 0)
|
|
|
|
|
(setq tab-width source-tab-width))
|
|
|
|
|
(indent-to indentation-offset)
|
|
|
|
|
(buffer-string)))
|
2023-06-27 07:23:01 +00:00
|
|
|
|
;; LaTeX-fragments are inline. Do not add indentation to their
|
|
|
|
|
;; first line.
|
|
|
|
|
(when preserve-fl (forward-line))
|
2021-08-30 21:18:41 +00:00
|
|
|
|
(while (not (eobp))
|
2023-06-27 07:23:01 +00:00
|
|
|
|
;; Keep empty src lines empty, even when src block is
|
|
|
|
|
;; indented on Org side.
|
|
|
|
|
;; See https://list.orgmode.org/725763.1632663635@apollo2.minshall.org/T/
|
2023-07-13 09:28:13 +00:00
|
|
|
|
(when (not (eolp)) ; not an empty line
|
|
|
|
|
(insert indent-str))
|
|
|
|
|
(forward-line))))))
|
|
|
|
|
|
|
|
|
|
(defun org-src--contents-for-write-back (write-back-buf)
|
|
|
|
|
"Populate WRITE-BACK-BUF with contents in the appropriate format.
|
|
|
|
|
Assume point is in the corresponding edit buffer."
|
|
|
|
|
(org-src--contents-for-write-back-1
|
|
|
|
|
write-back-buf
|
|
|
|
|
;; CONTENTS
|
|
|
|
|
(org-with-wide-buffer (buffer-string))
|
|
|
|
|
;; INDENTATION
|
|
|
|
|
(if org-src--preserve-indentation 0
|
|
|
|
|
(+ (or org-src--block-indentation 0)
|
|
|
|
|
(if (memq org-src--source-type '(example-block src-block))
|
|
|
|
|
org-src--content-indentation
|
|
|
|
|
0)))
|
|
|
|
|
;; PRESERVE-FL
|
|
|
|
|
(eq org-src--source-type 'latex-fragment)
|
|
|
|
|
;; TAB-WIDTH
|
|
|
|
|
org-src--tab-width
|
|
|
|
|
;; WRITE-BACK
|
|
|
|
|
org-src--allow-write-back))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
2015-04-26 08:32:20 +00:00
|
|
|
|
(defun org-src--edit-element
|
2017-08-21 09:27:41 +00:00
|
|
|
|
(datum name &optional initialize write-back contents remote)
|
2015-05-02 06:37:37 +00:00
|
|
|
|
"Edit DATUM contents in a dedicated buffer NAME.
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
2017-08-21 09:27:41 +00:00
|
|
|
|
INITIALIZE is a function to call upon creating the buffer.
|
2015-04-26 08:32:20 +00:00
|
|
|
|
|
|
|
|
|
When WRITE-BACK is non-nil, assume contents will replace original
|
2015-05-02 06:37:37 +00:00
|
|
|
|
region. Moreover, if it is a function, apply it in the edit
|
|
|
|
|
buffer, from point min, before returning the contents.
|
2015-04-26 08:32:20 +00:00
|
|
|
|
|
|
|
|
|
When CONTENTS is non-nil, display them in the edit buffer.
|
2015-05-02 06:37:37 +00:00
|
|
|
|
Otherwise, show DATUM contents as specified by
|
|
|
|
|
`org-src--contents-area'.
|
2015-04-26 08:32:20 +00:00
|
|
|
|
|
|
|
|
|
When REMOTE is non-nil, do not try to preserve point or mark when
|
|
|
|
|
moving from the edit area to the source.
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
|
|
|
|
Leave point in edit buffer."
|
2019-12-23 16:55:55 +00:00
|
|
|
|
(when (memq org-src-window-setup '(reorganize-frame
|
|
|
|
|
split-window-below
|
|
|
|
|
split-window-right))
|
|
|
|
|
(setq org-src--saved-temp-window-config (current-window-configuration)))
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(let* ((area (org-src--contents-area datum))
|
2015-05-22 18:59:31 +00:00
|
|
|
|
(beg (copy-marker (nth 0 area)))
|
|
|
|
|
(end (copy-marker (nth 1 area) t))
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(old-edit-buffer (org-src--edit-buffer beg end))
|
2015-05-22 18:59:31 +00:00
|
|
|
|
(contents (or contents (nth 2 area))))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(if (and old-edit-buffer
|
|
|
|
|
(or (not org-src-ask-before-returning-to-edit-buffer)
|
|
|
|
|
(y-or-n-p "Return to existing edit buffer ([n] will revert changes)? ")))
|
|
|
|
|
;; Move to existing buffer.
|
|
|
|
|
(org-src-switch-to-buffer old-edit-buffer 'return)
|
|
|
|
|
;; Discard old edit buffer.
|
|
|
|
|
(when old-edit-buffer
|
2015-02-18 01:05:57 +00:00
|
|
|
|
(with-current-buffer old-edit-buffer (org-src--remove-overlay))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(kill-buffer old-edit-buffer))
|
|
|
|
|
(let* ((org-mode-p (derived-mode-p 'org-mode))
|
2018-11-04 15:37:59 +00:00
|
|
|
|
(source-file-name (buffer-file-name (buffer-base-buffer)))
|
2017-04-29 09:45:45 +00:00
|
|
|
|
(source-tab-width (if indent-tabs-mode tab-width 0))
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(type (org-element-type datum))
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(block-ind (org-with-point-at (org-element-begin datum)
|
2021-08-30 21:18:41 +00:00
|
|
|
|
(cond
|
|
|
|
|
((save-excursion (skip-chars-backward " \t") (bolp))
|
2022-10-04 07:21:20 +00:00
|
|
|
|
(org-current-text-indentation))
|
2023-05-03 12:56:35 +00:00
|
|
|
|
((org-element-parent datum)
|
2021-08-30 21:18:41 +00:00
|
|
|
|
(org--get-expected-indentation
|
2023-05-03 12:56:35 +00:00
|
|
|
|
(org-element-parent datum) nil))
|
2022-10-04 07:21:20 +00:00
|
|
|
|
(t (org-current-text-indentation)))))
|
2019-10-09 01:00:50 +00:00
|
|
|
|
(content-ind org-edit-src-content-indentation)
|
2023-07-13 08:51:15 +00:00
|
|
|
|
(preserve-ind (org-src-preserve-indentation-p datum))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
;; Store relative positions of mark (if any) and point
|
|
|
|
|
;; within the edited area.
|
2015-04-26 08:32:20 +00:00
|
|
|
|
(point-coordinates (and (not remote)
|
|
|
|
|
(org-src--coordinates (point) beg end)))
|
|
|
|
|
(mark-coordinates (and (not remote)
|
|
|
|
|
(org-region-active-p)
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(let ((m (mark)))
|
|
|
|
|
(and (>= m beg) (>= end m)
|
|
|
|
|
(org-src--coordinates m beg end)))))
|
|
|
|
|
;; Generate a new edit buffer.
|
|
|
|
|
(buffer (generate-new-buffer name))
|
|
|
|
|
;; Add an overlay on top of source.
|
|
|
|
|
(overlay (org-src--make-source-overlay beg end buffer)))
|
|
|
|
|
;; Switch to edit buffer.
|
2009-10-27 18:11:09 +00:00
|
|
|
|
(org-src-switch-to-buffer buffer 'edit)
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
;; Insert contents.
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(insert contents)
|
2009-06-07 14:27:07 +00:00
|
|
|
|
(remove-text-properties (point-min) (point-max)
|
|
|
|
|
'(display nil invisible nil intangible nil))
|
2021-08-30 21:18:41 +00:00
|
|
|
|
(let ((lf (eq type 'latex-fragment)))
|
|
|
|
|
(unless preserve-ind (org-do-remove-indentation (and lf block-ind) lf)))
|
2009-08-24 12:47:58 +00:00
|
|
|
|
(set-buffer-modified-p nil)
|
2013-04-07 20:43:02 +00:00
|
|
|
|
(setq buffer-file-name nil)
|
2017-08-21 09:27:41 +00:00
|
|
|
|
;; Initialize buffer.
|
|
|
|
|
(when (functionp initialize)
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(let ((org-inhibit-startup t))
|
2023-05-31 10:45:19 +00:00
|
|
|
|
(condition-case-unless-debug e
|
2017-08-21 09:27:41 +00:00
|
|
|
|
(funcall initialize)
|
|
|
|
|
(error (message "Initialization fails with: %S"
|
|
|
|
|
(error-message-string e))))))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
;; Transmit buffer-local variables for exit function. It must
|
|
|
|
|
;; be done after initializing major mode, as this operation
|
|
|
|
|
;; may reset them otherwise.
|
2018-05-02 21:52:35 +00:00
|
|
|
|
(setq org-src--tab-width source-tab-width)
|
|
|
|
|
(setq org-src--from-org-mode org-mode-p)
|
|
|
|
|
(setq org-src--beg-marker beg)
|
|
|
|
|
(setq org-src--end-marker end)
|
|
|
|
|
(setq org-src--remote remote)
|
|
|
|
|
(setq org-src--source-type type)
|
2019-10-09 01:00:50 +00:00
|
|
|
|
(setq org-src--block-indentation block-ind)
|
|
|
|
|
(setq org-src--content-indentation content-ind)
|
2018-05-02 21:52:35 +00:00
|
|
|
|
(setq org-src--preserve-indentation preserve-ind)
|
|
|
|
|
(setq org-src--overlay overlay)
|
|
|
|
|
(setq org-src--allow-write-back write-back)
|
2018-11-04 15:37:59 +00:00
|
|
|
|
(setq org-src-source-file-name source-file-name)
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
;; Start minor mode.
|
|
|
|
|
(org-src-mode)
|
2020-07-02 17:30:14 +00:00
|
|
|
|
;; Clear undo information so we cannot undo back to the
|
|
|
|
|
;; initial empty buffer.
|
|
|
|
|
(buffer-disable-undo (current-buffer))
|
|
|
|
|
(buffer-enable-undo)
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
;; Move mark and point in edit buffer to the corresponding
|
|
|
|
|
;; location.
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(if remote
|
|
|
|
|
(progn
|
|
|
|
|
;; Put point at first non read-only character after
|
|
|
|
|
;; leading blank.
|
|
|
|
|
(goto-char
|
|
|
|
|
(or (text-property-any (point-min) (point-max) 'read-only nil)
|
|
|
|
|
(point-max)))
|
|
|
|
|
(skip-chars-forward " \r\t\n"))
|
|
|
|
|
;; Set mark and point.
|
|
|
|
|
(when mark-coordinates
|
|
|
|
|
(org-src--goto-coordinates mark-coordinates (point-min) (point-max))
|
|
|
|
|
(push-mark (point) 'no-message t)
|
|
|
|
|
(setq deactivate-mark nil))
|
|
|
|
|
(org-src--goto-coordinates
|
|
|
|
|
point-coordinates (point-min) (point-max)))))))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Fontification of source blocks
|
2009-06-07 14:27:07 +00:00
|
|
|
|
|
2021-12-06 02:48:10 +00:00
|
|
|
|
(defvar org-src-fontify-natively) ; Defined in org.el
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(defun org-src-font-lock-fontify-block (lang start end)
|
2021-09-30 20:07:15 +00:00
|
|
|
|
"Fontify code block between START and END using LANG's syntax.
|
2021-09-16 10:32:43 +00:00
|
|
|
|
This function is called by Emacs' automatic fontification, as long
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
as `org-src-fontify-natively' is non-nil."
|
2023-06-27 07:23:01 +00:00
|
|
|
|
(let ((modified (buffer-modified-p)) native-tab-width)
|
2022-12-26 08:55:26 +00:00
|
|
|
|
(remove-text-properties start end '(face nil))
|
|
|
|
|
(let ((lang-mode (org-src-get-lang-mode lang)))
|
|
|
|
|
(when (fboundp lang-mode)
|
|
|
|
|
(let ((string (buffer-substring-no-properties start end))
|
|
|
|
|
(org-buffer (current-buffer)))
|
|
|
|
|
(with-current-buffer
|
|
|
|
|
(get-buffer-create
|
|
|
|
|
(format " *org-src-fontification:%s*" lang-mode))
|
|
|
|
|
(let ((inhibit-modification-hooks nil))
|
|
|
|
|
(erase-buffer)
|
|
|
|
|
;; Add string and a final space to ensure property change.
|
|
|
|
|
(insert string " "))
|
|
|
|
|
(unless (eq major-mode lang-mode) (funcall lang-mode))
|
2023-06-27 07:23:01 +00:00
|
|
|
|
(setq native-tab-width tab-width)
|
2022-12-26 08:55:26 +00:00
|
|
|
|
(font-lock-ensure)
|
2024-03-13 12:31:11 +00:00
|
|
|
|
(let ((pos (point-min)) next
|
|
|
|
|
;; Difference between positions here and in org-buffer.
|
|
|
|
|
(offset (- start (point-min))))
|
2022-12-26 08:55:26 +00:00
|
|
|
|
(while (setq next (next-property-change pos))
|
|
|
|
|
;; Handle additional properties from font-lock, so as to
|
|
|
|
|
;; preserve, e.g., composition.
|
|
|
|
|
;; FIXME: We copy 'font-lock-face property explicitly because
|
|
|
|
|
;; `font-lock-mode' is not enabled in the buffers starting from
|
|
|
|
|
;; space and the remapping between 'font-lock-face and 'face
|
|
|
|
|
;; text properties may thus not be set. See commit
|
|
|
|
|
;; 453d634bc.
|
|
|
|
|
(dolist (prop (append '(font-lock-face face) font-lock-extra-managed-props))
|
|
|
|
|
(let ((new-prop (get-text-property pos prop)))
|
|
|
|
|
(when new-prop
|
|
|
|
|
(if (not (eq prop 'invisible))
|
|
|
|
|
(put-text-property
|
2024-03-13 12:31:11 +00:00
|
|
|
|
(+ offset pos) (+ offset next) prop new-prop
|
2022-12-26 08:55:26 +00:00
|
|
|
|
org-buffer)
|
|
|
|
|
;; Special case. `invisible' text property may
|
|
|
|
|
;; clash with Org folding. Do not assign
|
|
|
|
|
;; `invisible' text property directly. Use
|
|
|
|
|
;; property alias instead.
|
|
|
|
|
(let ((invisibility-spec
|
|
|
|
|
(or
|
|
|
|
|
;; ATOM spec.
|
|
|
|
|
(and (memq new-prop buffer-invisibility-spec)
|
|
|
|
|
new-prop)
|
|
|
|
|
;; (ATOM . ELLIPSIS) spec.
|
|
|
|
|
(assq new-prop buffer-invisibility-spec))))
|
|
|
|
|
(with-current-buffer org-buffer
|
|
|
|
|
;; Add new property alias.
|
|
|
|
|
(unless (memq 'org-src-invisible
|
|
|
|
|
(cdr (assq 'invisible char-property-alias-alist)))
|
|
|
|
|
(setq-local
|
|
|
|
|
char-property-alias-alist
|
|
|
|
|
(cons (cons 'invisible
|
|
|
|
|
(nconc (cdr (assq 'invisible char-property-alias-alist))
|
|
|
|
|
'(org-src-invisible)))
|
|
|
|
|
(remove (assq 'invisible char-property-alias-alist)
|
|
|
|
|
char-property-alias-alist))))
|
|
|
|
|
;; Carry over the invisibility spec, unless
|
|
|
|
|
;; already present. Note that there might
|
|
|
|
|
;; be conflicting invisibility specs from
|
|
|
|
|
;; different major modes. We cannot do much
|
|
|
|
|
;; about this then.
|
|
|
|
|
(when invisibility-spec
|
|
|
|
|
(add-to-invisibility-spec invisibility-spec))
|
|
|
|
|
(put-text-property
|
2024-03-13 12:31:11 +00:00
|
|
|
|
(+ offset pos) (+ offset next)
|
2022-12-26 08:55:26 +00:00
|
|
|
|
'org-src-invisible new-prop
|
|
|
|
|
org-buffer)))))))
|
|
|
|
|
(setq pos next)))
|
|
|
|
|
(set-buffer-modified-p nil)))))
|
|
|
|
|
;; Add Org faces.
|
|
|
|
|
(let ((src-face (nth 1 (assoc-string lang org-src-block-faces t))))
|
|
|
|
|
(when (or (facep src-face) (listp src-face))
|
|
|
|
|
(font-lock-append-text-property start end 'face src-face))
|
|
|
|
|
(font-lock-append-text-property start end 'face 'org-block))
|
2023-06-27 07:23:01 +00:00
|
|
|
|
;; Display native tab indentation characters as spaces
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char start)
|
|
|
|
|
(let ((indent-offset
|
2023-07-13 08:51:15 +00:00
|
|
|
|
(if (org-src-preserve-indentation-p) 0
|
2023-06-27 07:23:01 +00:00
|
|
|
|
(+ (progn (backward-char)
|
|
|
|
|
(org-current-text-indentation))
|
|
|
|
|
org-edit-src-content-indentation))))
|
|
|
|
|
(while (re-search-forward "^[ ]*\t" end t)
|
|
|
|
|
(let* ((b (and (eq indent-offset (move-to-column indent-offset))
|
|
|
|
|
(point)))
|
|
|
|
|
(e (progn (skip-chars-forward "\t") (point)))
|
|
|
|
|
(s (and b (make-string (* (- e b) native-tab-width) ? ))))
|
|
|
|
|
(when (and b (< b e)) (add-text-properties b e `(display ,s)))
|
|
|
|
|
(forward-char)))))
|
2022-12-26 08:55:26 +00:00
|
|
|
|
(add-text-properties
|
|
|
|
|
start end
|
|
|
|
|
'(font-lock-fontified t fontified t font-lock-multiline t))
|
|
|
|
|
(set-buffer-modified-p modified)))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
2021-07-12 18:43:29 +00:00
|
|
|
|
(defun org-fontify-inline-src-blocks (limit)
|
|
|
|
|
"Try to apply `org-fontify-inline-src-blocks-1'."
|
2023-05-31 10:45:19 +00:00
|
|
|
|
(condition-case-unless-debug nil
|
2021-07-12 18:43:29 +00:00
|
|
|
|
(org-fontify-inline-src-blocks-1 limit)
|
|
|
|
|
(error (message "Org mode fontification error in %S at %d"
|
|
|
|
|
(current-buffer)
|
|
|
|
|
(line-number-at-pos)))))
|
|
|
|
|
|
|
|
|
|
(defun org-fontify-inline-src-blocks-1 (limit)
|
|
|
|
|
"Fontify inline src_LANG blocks, from `point' up to LIMIT."
|
2021-11-30 13:00:18 +00:00
|
|
|
|
(let ((case-fold-search t))
|
|
|
|
|
;; The regexp below is copied from `org-element-inline-src-block-parser'.
|
|
|
|
|
(while (re-search-forward "\\_<src_\\([^ \t\n[{]+\\)[{[]?" limit t)
|
2021-07-12 18:43:29 +00:00
|
|
|
|
(let ((beg (match-beginning 0))
|
|
|
|
|
(lang-beg (match-beginning 1))
|
|
|
|
|
(lang-end (match-end 1))
|
|
|
|
|
pt)
|
2024-03-31 11:41:07 +00:00
|
|
|
|
(add-face-text-property beg lang-end 'org-inline-src-block)
|
|
|
|
|
(add-face-text-property beg lang-beg 'shadow)
|
|
|
|
|
(add-face-text-property lang-beg lang-end 'org-meta-line)
|
2021-07-12 18:43:29 +00:00
|
|
|
|
(setq pt (goto-char lang-end))
|
|
|
|
|
;; `org-element--parse-paired-brackets' doesn't take a limit, so to
|
|
|
|
|
;; prevent it searching the entire rest of the buffer we temporarily
|
|
|
|
|
;; narrow the active region.
|
|
|
|
|
(save-restriction
|
2021-11-30 13:00:18 +00:00
|
|
|
|
(narrow-to-region beg
|
|
|
|
|
(min limit (or (save-excursion
|
|
|
|
|
(and (search-forward"\n" limit t 2)
|
|
|
|
|
(point)))
|
|
|
|
|
(point-max))))
|
2021-07-12 18:43:29 +00:00
|
|
|
|
(when (ignore-errors (org-element--parse-paired-brackets ?\[))
|
2024-03-31 11:41:07 +00:00
|
|
|
|
(add-face-text-property pt (point) 'org-inline-src-block)
|
2021-07-12 18:43:29 +00:00
|
|
|
|
(setq pt (point)))
|
|
|
|
|
(when (ignore-errors (org-element--parse-paired-brackets ?\{))
|
|
|
|
|
(remove-text-properties pt (point) '(face nil))
|
2024-03-31 11:41:07 +00:00
|
|
|
|
(add-face-text-property pt (1+ pt) '(org-inline-src-block shadow))
|
2021-07-12 18:43:29 +00:00
|
|
|
|
(unless (= (1+ pt) (1- (point)))
|
|
|
|
|
(if org-src-fontify-natively
|
|
|
|
|
(org-src-font-lock-fontify-block
|
|
|
|
|
(buffer-substring-no-properties lang-beg lang-end)
|
|
|
|
|
(1+ pt) (1- (point)))
|
2021-11-30 13:00:18 +00:00
|
|
|
|
(font-lock-append-text-property
|
|
|
|
|
(1+ pt) (1- (point)) 'face 'org-inline-src-block)))
|
2024-03-31 11:41:07 +00:00
|
|
|
|
(add-face-text-property (1- (point)) (point) '(org-inline-src-block shadow))
|
2021-07-12 18:43:29 +00:00
|
|
|
|
(setq pt (point)))))
|
|
|
|
|
t)))
|
|
|
|
|
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
|
|
|
|
;;; Escape contents
|
2009-06-07 14:27:07 +00:00
|
|
|
|
|
2012-09-30 15:20:27 +00:00
|
|
|
|
(defun org-escape-code-in-region (beg end)
|
|
|
|
|
"Escape lines between BEG and END.
|
|
|
|
|
Escaping happens when a line starts with \"*\", \"#+\", \",*\" or
|
|
|
|
|
\",#+\" by appending a comma to it."
|
2012-09-28 18:47:14 +00:00
|
|
|
|
(interactive "r")
|
2012-09-30 15:20:27 +00:00
|
|
|
|
(save-excursion
|
2015-06-02 15:17:17 +00:00
|
|
|
|
(goto-char end)
|
2017-10-24 07:51:43 +00:00
|
|
|
|
(while (re-search-backward "^[ \t]*\\(,*\\(?:\\*\\|#\\+\\)\\)" beg t)
|
2015-06-02 15:17:17 +00:00
|
|
|
|
(save-excursion (replace-match ",\\1" nil nil nil 1)))))
|
2012-09-30 15:20:27 +00:00
|
|
|
|
|
|
|
|
|
(defun org-escape-code-in-string (s)
|
|
|
|
|
"Escape lines in string S.
|
|
|
|
|
Escaping happens when a line starts with \"*\", \"#+\", \",*\" or
|
|
|
|
|
\",#+\" by appending a comma to it."
|
2017-10-24 07:51:43 +00:00
|
|
|
|
(replace-regexp-in-string "^[ \t]*\\(,*\\(?:\\*\\|#\\+\\)\\)" ",\\1"
|
|
|
|
|
s nil nil 1))
|
2012-09-30 15:20:27 +00:00
|
|
|
|
|
|
|
|
|
(defun org-unescape-code-in-region (beg end)
|
|
|
|
|
"Un-escape lines between BEG and END.
|
|
|
|
|
Un-escaping happens by removing the first comma on lines starting
|
|
|
|
|
with \",*\", \",#+\", \",,*\" and \",,#+\"."
|
|
|
|
|
(interactive "r")
|
|
|
|
|
(save-excursion
|
2015-06-02 15:17:17 +00:00
|
|
|
|
(goto-char end)
|
2017-10-24 07:51:43 +00:00
|
|
|
|
(while (re-search-backward "^[ \t]*,*\\(,\\)\\(?:\\*\\|#\\+\\)" beg t)
|
2015-06-02 15:17:17 +00:00
|
|
|
|
(save-excursion (replace-match "" nil nil nil 1)))))
|
2012-09-30 15:20:27 +00:00
|
|
|
|
|
|
|
|
|
(defun org-unescape-code-in-string (s)
|
|
|
|
|
"Un-escape lines in string S.
|
|
|
|
|
Un-escaping happens by removing the first comma on lines starting
|
|
|
|
|
with \",*\", \",#+\", \",,*\" and \",,#+\"."
|
|
|
|
|
(replace-regexp-in-string
|
2017-10-24 07:51:43 +00:00
|
|
|
|
"^[ \t]*,*\\(,\\)\\(?:\\*\\|#\\+\\)" "" s nil nil 1))
|
2012-09-28 18:47:14 +00:00
|
|
|
|
|
2009-06-07 14:27:07 +00:00
|
|
|
|
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
|
|
|
|
;;; Org src minor mode
|
2012-03-19 20:38:12 +00:00
|
|
|
|
|
2015-05-01 07:49:14 +00:00
|
|
|
|
(defvar org-src-mode-map
|
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
|
(define-key map "\C-c'" 'org-edit-src-exit)
|
|
|
|
|
(define-key map "\C-c\C-k" 'org-edit-src-abort)
|
|
|
|
|
(define-key map "\C-x\C-s" 'org-edit-src-save)
|
|
|
|
|
map))
|
2012-03-19 20:38:12 +00:00
|
|
|
|
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(define-minor-mode org-src-mode
|
2015-05-01 08:29:05 +00:00
|
|
|
|
"Minor mode for language major mode buffers generated by Org.
|
2015-05-01 07:49:14 +00:00
|
|
|
|
\\<org-mode-map>
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
This minor mode is turned on in two situations:
|
2016-10-15 15:36:47 +00:00
|
|
|
|
- when editing a source code snippet with `\\[org-edit-special]'
|
2015-05-01 07:49:14 +00:00
|
|
|
|
- when formatting a source code snippet for export with htmlize.
|
|
|
|
|
|
|
|
|
|
\\{org-src-mode-map}
|
|
|
|
|
|
|
|
|
|
See also `org-src-mode-hook'."
|
2021-04-12 03:47:14 +00:00
|
|
|
|
:lighter " OrgSrc"
|
2015-04-29 11:16:21 +00:00
|
|
|
|
(when org-edit-src-persistent-message
|
2018-05-02 21:35:00 +00:00
|
|
|
|
(setq header-line-format
|
|
|
|
|
(substitute-command-keys
|
|
|
|
|
(if org-src--allow-write-back
|
|
|
|
|
"Edit, then exit with `\\[org-edit-src-exit]' or abort with \
|
2016-10-15 15:36:47 +00:00
|
|
|
|
`\\[org-edit-src-abort]'"
|
2018-05-02 21:35:00 +00:00
|
|
|
|
"Exit with `\\[org-edit-src-exit]' or abort with \
|
2016-10-15 15:36:47 +00:00
|
|
|
|
`\\[org-edit-src-abort]'"))))
|
2015-04-29 11:21:17 +00:00
|
|
|
|
;; Possibly activate various auto-save features (for the edit buffer
|
2015-04-29 11:16:21 +00:00
|
|
|
|
;; or the source buffer).
|
|
|
|
|
(when org-edit-src-turn-on-auto-save
|
|
|
|
|
(setq buffer-auto-save-file-name
|
|
|
|
|
(concat (make-temp-name "org-src-")
|
|
|
|
|
(format-time-string "-%Y-%d-%m")
|
|
|
|
|
".txt")))
|
2018-07-01 22:45:12 +00:00
|
|
|
|
(unless (or org-src--auto-save-timer
|
|
|
|
|
(= 0 org-edit-src-auto-save-idle-delay))
|
2015-04-29 11:21:17 +00:00
|
|
|
|
(setq org-src--auto-save-timer
|
|
|
|
|
(run-with-idle-timer
|
|
|
|
|
org-edit-src-auto-save-idle-delay t
|
|
|
|
|
(lambda ()
|
2015-05-26 15:06:53 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(let (edit-flag)
|
|
|
|
|
(dolist (b (buffer-list))
|
|
|
|
|
(with-current-buffer b
|
|
|
|
|
(when (org-src-edit-buffer-p)
|
|
|
|
|
(unless edit-flag (setq edit-flag t))
|
|
|
|
|
(when (buffer-modified-p) (org-edit-src-save)))))
|
|
|
|
|
(unless edit-flag
|
|
|
|
|
(cancel-timer org-src--auto-save-timer)
|
|
|
|
|
(setq org-src--auto-save-timer nil)))))))))
|
2009-06-07 14:27:07 +00:00
|
|
|
|
|
2009-08-24 12:47:58 +00:00
|
|
|
|
(defun org-src-mode-configure-edit-buffer ()
|
2018-04-26 22:25:15 +00:00
|
|
|
|
"Configure the src edit buffer."
|
2016-06-23 12:18:38 +00:00
|
|
|
|
(when (bound-and-true-p org-src--from-org-mode)
|
Remove final parts of XEmacs compatibility code
* lisp/org-compat.el: Declare `org-add-hook', `org-decompose-region',
`org-detach-overlay', `org-file-equal-p', `org-float-time',
`org-indent-line-to', `org-indent-to-column', `org-looking-at-p',
`org-looking-back', `org-propertize', `org-re' and
`org-select-frame-set-input-focus' as obsolete.
(org-overlay-display, org-overlay-before-string, org-find-overlays):
Move to "org.el"
(org-xemacs-key-equivalents, org-xemacs-p): Remove variables.
(org-region-active-p): Drop XEmacs support.
(org-xemacs-without-invisibility): Remove macro.
(org-get-x-clipboard-compat): Remove function.
* lisp/org-macs.el (org-match-string-no-properties): Remove function.
* lisp/ob-core.el:
* lisp/org-agenda.el:
* lisp/org-archive.el:
* lisp/org-clock.el:
* lisp/org-colview.el:
* lisp/org-crypt.el:
* lisp/org-element.el:
* lisp/org-faces.el:
* lisp/org-feed.el:
* lisp/org-footnote.el:
* lisp/org-habit.el:
* lisp/org-id.el:
* lisp/org-indent.el:
* lisp/org-inlinetask.el:
* lisp/org-lint.el:
* lisp/org-list.el:
* lisp/org-mouse.el:
* lisp/org-pcomplete.el:
* lisp/org-src.el:
* lisp/org-table.el:
* lisp/org-timer.el:
* lisp/org.el:
* lisp/ox-ascii.el:
* lisp/ox-odt.el:
* lisp/ox.el:
* contrib/lisp/org-notify.el:
* contrib/lisp/ox-taskjuggler.el:
* contrib/lisp/org-wikinodes.el:
* testing/lisp/test-org-src.el:
* testing/lisp/test-org.el: Silence byte-compiler.
2016-05-26 10:18:00 +00:00
|
|
|
|
(add-hook 'kill-buffer-hook #'org-src--remove-overlay nil 'local)
|
2016-06-23 12:18:38 +00:00
|
|
|
|
(if (bound-and-true-p org-src--allow-write-back)
|
2010-04-22 21:37:35 +00:00
|
|
|
|
(progn
|
|
|
|
|
(setq buffer-offer-save t)
|
2018-05-02 21:35:00 +00:00
|
|
|
|
(setq write-contents-functions '(org-edit-src-save)))
|
2010-04-22 21:37:35 +00:00
|
|
|
|
(setq buffer-read-only t))))
|
2009-08-24 12:47:58 +00:00
|
|
|
|
|
Remove final parts of XEmacs compatibility code
* lisp/org-compat.el: Declare `org-add-hook', `org-decompose-region',
`org-detach-overlay', `org-file-equal-p', `org-float-time',
`org-indent-line-to', `org-indent-to-column', `org-looking-at-p',
`org-looking-back', `org-propertize', `org-re' and
`org-select-frame-set-input-focus' as obsolete.
(org-overlay-display, org-overlay-before-string, org-find-overlays):
Move to "org.el"
(org-xemacs-key-equivalents, org-xemacs-p): Remove variables.
(org-region-active-p): Drop XEmacs support.
(org-xemacs-without-invisibility): Remove macro.
(org-get-x-clipboard-compat): Remove function.
* lisp/org-macs.el (org-match-string-no-properties): Remove function.
* lisp/ob-core.el:
* lisp/org-agenda.el:
* lisp/org-archive.el:
* lisp/org-clock.el:
* lisp/org-colview.el:
* lisp/org-crypt.el:
* lisp/org-element.el:
* lisp/org-faces.el:
* lisp/org-feed.el:
* lisp/org-footnote.el:
* lisp/org-habit.el:
* lisp/org-id.el:
* lisp/org-indent.el:
* lisp/org-inlinetask.el:
* lisp/org-lint.el:
* lisp/org-list.el:
* lisp/org-mouse.el:
* lisp/org-pcomplete.el:
* lisp/org-src.el:
* lisp/org-table.el:
* lisp/org-timer.el:
* lisp/org.el:
* lisp/ox-ascii.el:
* lisp/ox-odt.el:
* lisp/ox.el:
* contrib/lisp/org-notify.el:
* contrib/lisp/ox-taskjuggler.el:
* contrib/lisp/org-wikinodes.el:
* testing/lisp/test-org-src.el:
* testing/lisp/test-org.el: Silence byte-compiler.
2016-05-26 10:18:00 +00:00
|
|
|
|
(add-hook 'org-src-mode-hook #'org-src-mode-configure-edit-buffer)
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
2009-08-24 12:47:58 +00:00
|
|
|
|
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
|
|
|
|
;;; Babel related functions
|
2010-08-17 00:55:24 +00:00
|
|
|
|
|
|
|
|
|
(defun org-src-associate-babel-session (info)
|
2021-09-30 20:07:15 +00:00
|
|
|
|
"Associate edit buffer with comint session.
|
2022-06-30 15:33:03 +00:00
|
|
|
|
INFO should be a list similar in format to the return value of
|
2021-09-30 20:07:15 +00:00
|
|
|
|
`org-babel-get-src-block-info'."
|
2010-08-17 00:55:24 +00:00
|
|
|
|
(interactive)
|
2016-09-22 17:45:15 +00:00
|
|
|
|
(let ((session (cdr (assq :session (nth 2 info)))))
|
2010-08-17 00:55:24 +00:00
|
|
|
|
(and session (not (string= session "none"))
|
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 19:57:31 +00:00
|
|
|
|
(let ((f (intern (format "org-babel-%s-associate-session"
|
|
|
|
|
(nth 0 info)))))
|
|
|
|
|
(and (fboundp f) (funcall f session))))))
|
2010-08-17 00:55:24 +00:00
|
|
|
|
|
|
|
|
|
(defun org-src-babel-configure-edit-buffer ()
|
2021-09-30 20:07:15 +00:00
|
|
|
|
"Configure src editing buffer."
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(when org-src--babel-info
|
2024-01-05 13:31:31 +00:00
|
|
|
|
(org-src-associate-babel-session org-src--babel-info)))
|
|
|
|
|
|
|
|
|
|
(add-hook 'org-src-mode-hook #'org-src-babel-configure-edit-buffer)
|
2010-08-17 00:55:24 +00:00
|
|
|
|
|
2016-08-19 14:19:36 +00:00
|
|
|
|
|
|
|
|
|
;;; Public API
|
|
|
|
|
|
|
|
|
|
(defmacro org-src-do-at-code-block (&rest body)
|
|
|
|
|
"Execute BODY from an edit buffer in the Org mode buffer."
|
|
|
|
|
(declare (debug (body)))
|
|
|
|
|
`(let ((beg-marker org-src--beg-marker))
|
|
|
|
|
(when beg-marker
|
|
|
|
|
(with-current-buffer (marker-buffer beg-marker)
|
|
|
|
|
(goto-char beg-marker)
|
|
|
|
|
,@body))))
|
|
|
|
|
|
2010-08-18 02:37:19 +00:00
|
|
|
|
(defun org-src-do-key-sequence-at-code-block (&optional key)
|
|
|
|
|
"Execute key sequence at code block in the source Org buffer.
|
|
|
|
|
The command bound to KEY in the Org-babel key map is executed
|
|
|
|
|
remotely with point temporarily at the start of the code block in
|
|
|
|
|
the Org buffer.
|
|
|
|
|
|
|
|
|
|
This command is not bound to a key by default, to avoid conflicts
|
2012-07-11 16:36:22 +00:00
|
|
|
|
with language major mode bindings. To bind it to C-c @ in all
|
2010-08-18 02:37:19 +00:00
|
|
|
|
language major modes, you could use
|
|
|
|
|
|
2015-09-21 04:23:36 +00:00
|
|
|
|
(add-hook \\='org-src-mode-hook
|
2010-08-18 02:37:19 +00:00
|
|
|
|
(lambda () (define-key org-src-mode-map \"\\C-c@\"
|
2015-09-21 04:23:36 +00:00
|
|
|
|
\\='org-src-do-key-sequence-at-code-block)))
|
2010-08-18 02:37:19 +00:00
|
|
|
|
|
|
|
|
|
In that case, for example, C-c @ t issued in code edit buffers
|
|
|
|
|
would tangle the current Org code block, C-c @ e would execute
|
|
|
|
|
the block and C-c @ h would display the other available
|
|
|
|
|
Org-babel commands."
|
|
|
|
|
(interactive "kOrg-babel key: ")
|
|
|
|
|
(if (equal key (kbd "C-g")) (keyboard-quit)
|
|
|
|
|
(org-edit-src-save)
|
|
|
|
|
(org-src-do-at-code-block
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(call-interactively (lookup-key org-babel-map key)))))
|
|
|
|
|
|
2019-04-07 07:12:40 +00:00
|
|
|
|
(defun org-src-get-lang-mode (lang)
|
|
|
|
|
"Return major mode that should be used for LANG.
|
|
|
|
|
LANG is a string, and the returned major mode is a symbol."
|
|
|
|
|
(intern
|
|
|
|
|
(concat
|
|
|
|
|
(let ((l (or (cdr (assoc lang org-src-lang-modes)) lang)))
|
|
|
|
|
(if (symbolp l) (symbol-name l) l))
|
|
|
|
|
"-mode")))
|
|
|
|
|
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(defun org-src-edit-buffer-p (&optional buffer)
|
|
|
|
|
"Non-nil when current buffer is a source editing buffer.
|
|
|
|
|
If BUFFER is non-nil, test it instead."
|
|
|
|
|
(let ((buffer (org-base-buffer (or buffer (current-buffer)))))
|
|
|
|
|
(and (buffer-live-p buffer)
|
|
|
|
|
(local-variable-p 'org-src--beg-marker buffer)
|
|
|
|
|
(local-variable-p 'org-src--end-marker buffer))))
|
|
|
|
|
|
2018-11-04 14:26:04 +00:00
|
|
|
|
(defun org-src-source-buffer ()
|
|
|
|
|
"Return source buffer edited in current buffer.
|
|
|
|
|
Raise an error when current buffer is not a source editing buffer."
|
|
|
|
|
(unless (org-src-edit-buffer-p) (error "Not in a source buffer"))
|
|
|
|
|
(or (marker-buffer org-src--beg-marker)
|
|
|
|
|
(error "No source buffer available for current editing session")))
|
|
|
|
|
|
|
|
|
|
(defun org-src-source-type ()
|
|
|
|
|
"Return type of element edited in current buffer.
|
|
|
|
|
Raise an error when current buffer is not a source editing buffer."
|
|
|
|
|
(unless (org-src-edit-buffer-p) (error "Not in a source buffer"))
|
|
|
|
|
org-src--source-type)
|
|
|
|
|
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(defun org-src-switch-to-buffer (buffer context)
|
2021-09-30 20:07:15 +00:00
|
|
|
|
"Switch to BUFFER considering CONTEXT and `org-src-window-setup'."
|
2016-07-25 14:01:15 +00:00
|
|
|
|
(pcase org-src-window-setup
|
2020-01-19 16:28:36 +00:00
|
|
|
|
(`plain
|
|
|
|
|
(when (eq context 'exit) (quit-restore-window))
|
|
|
|
|
(pop-to-buffer buffer))
|
2016-07-25 14:01:15 +00:00
|
|
|
|
(`current-window (pop-to-buffer-same-window buffer))
|
|
|
|
|
(`other-window
|
2020-01-22 04:39:14 +00:00
|
|
|
|
(let ((cur-win (selected-window)))
|
2024-01-24 13:54:30 +00:00
|
|
|
|
(switch-to-buffer-other-window buffer)
|
2020-01-22 04:39:14 +00:00
|
|
|
|
(when (eq context 'exit) (quit-restore-window cur-win))))
|
2018-03-12 17:23:52 +00:00
|
|
|
|
(`split-window-below
|
2019-01-22 17:03:04 +00:00
|
|
|
|
(if (eq context 'exit)
|
|
|
|
|
(delete-window)
|
|
|
|
|
(select-window (split-window-vertically)))
|
2018-03-12 17:23:52 +00:00
|
|
|
|
(pop-to-buffer-same-window buffer))
|
2019-07-11 09:24:15 +00:00
|
|
|
|
(`split-window-right
|
|
|
|
|
(if (eq context 'exit)
|
|
|
|
|
(delete-window)
|
|
|
|
|
(select-window (split-window-horizontally)))
|
|
|
|
|
(pop-to-buffer-same-window buffer))
|
2016-07-25 14:01:15 +00:00
|
|
|
|
(`other-frame
|
|
|
|
|
(pcase context
|
|
|
|
|
(`exit
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(let ((frame (selected-frame)))
|
|
|
|
|
(switch-to-buffer-other-frame buffer)
|
|
|
|
|
(delete-frame frame)))
|
2016-07-25 14:01:15 +00:00
|
|
|
|
(`save
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(kill-buffer (current-buffer))
|
2016-06-23 08:00:00 +00:00
|
|
|
|
(pop-to-buffer-same-window buffer))
|
2016-07-25 14:01:15 +00:00
|
|
|
|
(_ (switch-to-buffer-other-frame buffer))))
|
|
|
|
|
(`reorganize-frame
|
2024-04-07 10:34:13 +00:00
|
|
|
|
(pcase context
|
|
|
|
|
(`edit (pop-to-buffer buffer '(org-display-buffer-split)))
|
2024-04-07 13:02:31 +00:00
|
|
|
|
(`exit (pop-to-buffer buffer '(org-display-buffer-full-frame)))
|
2024-04-07 10:34:13 +00:00
|
|
|
|
(_ (switch-to-buffer-other-window buffer))))
|
2016-07-25 14:01:15 +00:00
|
|
|
|
(`switch-invisibly (set-buffer buffer))
|
|
|
|
|
(_
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(message "Invalid value %s for `org-src-window-setup'"
|
|
|
|
|
org-src-window-setup)
|
2016-06-23 08:00:00 +00:00
|
|
|
|
(pop-to-buffer-same-window buffer))))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
2016-08-17 21:43:38 +00:00
|
|
|
|
(defun org-src-coderef-format (&optional element)
|
|
|
|
|
"Return format string for block at point.
|
2016-08-08 12:04:11 +00:00
|
|
|
|
|
2016-08-17 21:43:38 +00:00
|
|
|
|
When optional argument ELEMENT is provided, use that block.
|
|
|
|
|
Otherwise, assume point is either at a source block, at an
|
|
|
|
|
example block.
|
|
|
|
|
|
|
|
|
|
If point is in an edit buffer, retrieve format string associated
|
|
|
|
|
to the remote source block."
|
|
|
|
|
(cond
|
|
|
|
|
((and element (org-element-property :label-fmt element)))
|
|
|
|
|
((org-src-edit-buffer-p) (org-src-do-at-code-block (org-src-coderef-format)))
|
|
|
|
|
((org-element-property :label-fmt (org-element-at-point)))
|
|
|
|
|
(t org-coderef-label-format)))
|
|
|
|
|
|
|
|
|
|
(defun org-src-coderef-regexp (fmt &optional label)
|
|
|
|
|
"Return regexp matching a coderef format string FMT.
|
|
|
|
|
|
|
|
|
|
When optional argument LABEL is non-nil, match coderef for that
|
|
|
|
|
label only.
|
2016-08-08 12:04:11 +00:00
|
|
|
|
|
|
|
|
|
Match group 1 contains the full coderef string with surrounding
|
|
|
|
|
white spaces. Match group 2 contains the same string without any
|
2016-08-17 21:43:38 +00:00
|
|
|
|
surrounding space. Match group 3 contains the label.
|
|
|
|
|
|
|
|
|
|
A coderef format regexp can only match at the end of a line."
|
2016-12-07 22:11:10 +00:00
|
|
|
|
(format "\\([ \t]*\\(%s\\)[ \t]*\\)$"
|
2016-08-17 21:43:38 +00:00
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
"%s"
|
2016-08-17 21:48:53 +00:00
|
|
|
|
(if label (regexp-quote label) "\\([-a-zA-Z0-9_][-a-zA-Z0-9_ ]*\\)")
|
2016-08-17 21:43:38 +00:00
|
|
|
|
(regexp-quote fmt)
|
|
|
|
|
nil t)))
|
2016-08-08 12:04:11 +00:00
|
|
|
|
|
2015-04-26 08:40:30 +00:00
|
|
|
|
(defun org-edit-footnote-reference ()
|
|
|
|
|
"Edit definition of footnote reference at point."
|
|
|
|
|
(interactive)
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(let* ((context (org-element-context))
|
|
|
|
|
(label (org-element-property :label context)))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(unless (and (org-element-type-p context 'footnote-reference)
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(org-src--on-datum-p context))
|
2015-04-26 12:57:36 +00:00
|
|
|
|
(user-error "Not on a footnote reference"))
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(unless label (user-error "Cannot edit remotely anonymous footnotes"))
|
|
|
|
|
(let* ((definition (org-with-wide-buffer
|
|
|
|
|
(org-footnote-goto-definition label)
|
2015-08-14 14:46:09 +00:00
|
|
|
|
(backward-char)
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(org-element-context)))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(inline? (org-element-type-p definition 'footnote-reference))
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(contents
|
2017-06-07 22:57:38 +00:00
|
|
|
|
(org-with-wide-buffer
|
|
|
|
|
(buffer-substring-no-properties
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(or (org-element-post-affiliated definition)
|
|
|
|
|
(org-element-begin definition))
|
2017-06-07 22:57:38 +00:00
|
|
|
|
(cond
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(inline? (1+ (org-element-contents-end definition)))
|
|
|
|
|
((org-element-contents-end definition))
|
|
|
|
|
(t (goto-char (org-element-post-affiliated definition))
|
2017-06-07 22:57:38 +00:00
|
|
|
|
(line-end-position)))))))
|
|
|
|
|
(add-text-properties
|
|
|
|
|
0
|
|
|
|
|
(progn (string-match (if inline? "\\`\\[fn:.*?:" "\\`.*?\\]") contents)
|
|
|
|
|
(match-end 0))
|
|
|
|
|
'(read-only "Cannot edit footnote label" front-sticky t rear-nonsticky t)
|
|
|
|
|
contents)
|
|
|
|
|
(when inline?
|
|
|
|
|
(let ((l (length contents)))
|
|
|
|
|
(add-text-properties
|
|
|
|
|
(1- l) l
|
|
|
|
|
'(read-only "Cannot edit past footnote reference"
|
|
|
|
|
front-sticky nil rear-nonsticky nil)
|
|
|
|
|
contents)))
|
2015-04-26 12:57:36 +00:00
|
|
|
|
(org-src--edit-element
|
2015-05-02 06:37:37 +00:00
|
|
|
|
definition
|
|
|
|
|
(format "*Edit footnote [%s]*" label)
|
2017-08-21 09:27:41 +00:00
|
|
|
|
(let ((source (current-buffer)))
|
|
|
|
|
(lambda ()
|
|
|
|
|
(org-mode)
|
|
|
|
|
(org-clone-local-variables source)))
|
2017-06-07 22:57:38 +00:00
|
|
|
|
(lambda ()
|
|
|
|
|
(if (not inline?) (delete-region (point) (search-forward "]"))
|
|
|
|
|
(delete-region (point) (search-forward ":" nil t 2))
|
|
|
|
|
(delete-region (1- (point-max)) (point-max))
|
|
|
|
|
(when (re-search-forward "\n[ \t]*\n" nil t)
|
|
|
|
|
(user-error "Inline definitions cannot contain blank lines"))
|
|
|
|
|
;; If footnote reference belongs to a table, make sure to
|
|
|
|
|
;; remove any newline characters in order to preserve
|
|
|
|
|
;; table's structure.
|
2023-05-18 11:35:35 +00:00
|
|
|
|
(when (org-element-lineage definition 'table-cell)
|
2020-05-25 10:36:35 +00:00
|
|
|
|
(while (search-forward "\n" nil t) (replace-match " ")))))
|
2017-06-07 22:57:38 +00:00
|
|
|
|
contents
|
2017-08-21 09:27:41 +00:00
|
|
|
|
'remote))
|
2015-04-26 12:57:36 +00:00
|
|
|
|
;; Report success.
|
|
|
|
|
t))
|
2015-04-26 08:40:30 +00:00
|
|
|
|
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(defun org-edit-table.el ()
|
|
|
|
|
"Edit \"table.el\" table at point.
|
2016-10-15 15:36:47 +00:00
|
|
|
|
\\<org-src-mode-map>
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
A new buffer is created and the table is copied into it. Then
|
|
|
|
|
the table is recognized with `table-recognize'. When done
|
2016-10-15 15:36:47 +00:00
|
|
|
|
editing, exit with `\\[org-edit-src-exit]'. The edited text will \
|
|
|
|
|
then replace
|
|
|
|
|
the area in the Org mode buffer.
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
|
|
|
|
Throw an error when not at such a table."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((element (org-element-at-point)))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(unless (and (org-element-type-p element 'table)
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(eq (org-element-property :type element) 'table.el)
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(org-src--on-datum-p element))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(user-error "Not in a table.el table"))
|
|
|
|
|
(org-src--edit-element
|
|
|
|
|
element
|
|
|
|
|
(org-src--construct-edit-buffer-name (buffer-name) "Table")
|
|
|
|
|
#'text-mode t)
|
2016-06-23 12:18:38 +00:00
|
|
|
|
(when (bound-and-true-p flyspell-mode) (flyspell-mode -1))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(table-recognize)
|
|
|
|
|
t))
|
|
|
|
|
|
2020-05-24 15:35:33 +00:00
|
|
|
|
(defun org-edit-latex-fragment ()
|
|
|
|
|
"Edit LaTeX fragment at point."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((context (org-element-context)))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(unless (and (org-element-type-p context 'latex-fragment)
|
2020-05-24 15:35:33 +00:00
|
|
|
|
(org-src--on-datum-p context))
|
|
|
|
|
(user-error "Not on a LaTeX fragment"))
|
|
|
|
|
(let* ((contents
|
|
|
|
|
(buffer-substring-no-properties
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(org-element-begin context)
|
|
|
|
|
(- (org-element-end context)
|
|
|
|
|
(org-element-post-blank context))))
|
2020-05-26 21:09:52 +00:00
|
|
|
|
(delim-length (if (string-match "\\`\\$[^$]" contents) 1 2)))
|
2020-05-24 15:35:33 +00:00
|
|
|
|
;; Make the LaTeX deliminators read-only.
|
|
|
|
|
(add-text-properties 0 delim-length
|
|
|
|
|
(list 'read-only "Cannot edit LaTeX deliminator"
|
|
|
|
|
'front-sticky t
|
|
|
|
|
'rear-nonsticky t)
|
|
|
|
|
contents)
|
|
|
|
|
(let ((l (length contents)))
|
|
|
|
|
(add-text-properties (- l delim-length) l
|
|
|
|
|
(list 'read-only "Cannot edit LaTeX deliminator"
|
|
|
|
|
'front-sticky nil
|
|
|
|
|
'rear-nonsticky nil)
|
|
|
|
|
contents))
|
|
|
|
|
(org-src--edit-element
|
|
|
|
|
context
|
|
|
|
|
(org-src--construct-edit-buffer-name (buffer-name) "LaTeX fragment")
|
|
|
|
|
(org-src-get-lang-mode "latex")
|
|
|
|
|
(lambda ()
|
|
|
|
|
;; Blank lines break things, replace with a single newline.
|
|
|
|
|
(while (re-search-forward "\n[ \t]*\n" nil t) (replace-match "\n"))
|
|
|
|
|
;; If within a table a newline would disrupt the structure,
|
|
|
|
|
;; so remove newlines.
|
|
|
|
|
(goto-char (point-min))
|
2023-05-18 11:35:35 +00:00
|
|
|
|
(when (org-element-lineage context 'table-cell)
|
2020-05-24 15:35:33 +00:00
|
|
|
|
(while (search-forward "\n" nil t) (replace-match " "))))
|
|
|
|
|
contents))
|
|
|
|
|
t))
|
|
|
|
|
|
2017-02-01 20:30:54 +00:00
|
|
|
|
(defun org-edit-latex-environment ()
|
|
|
|
|
"Edit LaTeX environment at point.
|
|
|
|
|
\\<org-src-mode-map>
|
|
|
|
|
The LaTeX environment is copied into a new buffer. Major mode is
|
|
|
|
|
set to the one associated to \"latex\" in `org-src-lang-modes',
|
|
|
|
|
or to `latex-mode' if there is none.
|
|
|
|
|
|
|
|
|
|
When done, exit with `\\[org-edit-src-exit]'. The edited text \
|
|
|
|
|
will then replace
|
|
|
|
|
the LaTeX environment in the Org mode buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((element (org-element-at-point)))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(unless (and (org-element-type-p element 'latex-environment)
|
2017-02-01 20:30:54 +00:00
|
|
|
|
(org-src--on-datum-p element))
|
|
|
|
|
(user-error "Not in a LaTeX environment"))
|
|
|
|
|
(org-src--edit-element
|
|
|
|
|
element
|
|
|
|
|
(org-src--construct-edit-buffer-name (buffer-name) "LaTeX environment")
|
2019-04-07 07:12:40 +00:00
|
|
|
|
(org-src-get-lang-mode "latex")
|
2017-02-01 20:30:54 +00:00
|
|
|
|
t)
|
|
|
|
|
t))
|
|
|
|
|
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(defun org-edit-export-block ()
|
|
|
|
|
"Edit export block at point.
|
2016-10-15 15:36:47 +00:00
|
|
|
|
\\<org-src-mode-map>
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
A new buffer is created and the block is copied into it, and the
|
|
|
|
|
buffer is switched into an appropriate major mode. See also
|
2016-10-15 15:36:47 +00:00
|
|
|
|
`org-src-lang-modes'.
|
|
|
|
|
|
|
|
|
|
When done, exit with `\\[org-edit-src-exit]'. The edited text \
|
|
|
|
|
will then replace
|
|
|
|
|
the area in the Org mode buffer.
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
|
|
|
|
Throw an error when not at an export block."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((element (org-element-at-point)))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(unless (and (org-element-type-p element 'export-block)
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(org-src--on-datum-p element))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(user-error "Not in an export block"))
|
2017-09-07 13:27:55 +00:00
|
|
|
|
(let* ((type (downcase (or (org-element-property :type element)
|
|
|
|
|
;; Missing export-block type. Fallback
|
|
|
|
|
;; to default mode.
|
|
|
|
|
"fundamental")))
|
2019-04-07 07:12:40 +00:00
|
|
|
|
(mode (org-src-get-lang-mode type)))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(unless (functionp mode) (error "No such language mode: %s" mode))
|
|
|
|
|
(org-src--edit-element
|
2015-04-26 08:04:55 +00:00
|
|
|
|
element
|
|
|
|
|
(org-src--construct-edit-buffer-name (buffer-name) type)
|
|
|
|
|
mode
|
|
|
|
|
(lambda () (org-escape-code-in-region (point-min) (point-max)))))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
t))
|
|
|
|
|
|
2022-07-30 05:24:10 +00:00
|
|
|
|
(defun org-edit-comment-block ()
|
|
|
|
|
"Edit comment block at point.
|
|
|
|
|
\\<org-src-mode-map>
|
|
|
|
|
A new buffer is created and the block is copied into it, and the
|
|
|
|
|
buffer is switched into Org mode.
|
|
|
|
|
|
2022-08-20 06:27:17 +00:00
|
|
|
|
When done, exit with `\\[org-edit-src-exit]'. The edited text will
|
|
|
|
|
then replace the area in the Org mode buffer.
|
2022-07-30 05:24:10 +00:00
|
|
|
|
|
|
|
|
|
Throw an error when not at a comment block."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((element (org-element-at-point)))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(unless (and (org-element-type-p element 'comment-block)
|
2022-07-30 05:24:10 +00:00
|
|
|
|
(org-src--on-datum-p element))
|
|
|
|
|
(user-error "Not in a comment block"))
|
|
|
|
|
(org-src--edit-element
|
|
|
|
|
element
|
|
|
|
|
(org-src--construct-edit-buffer-name (buffer-name) "org")
|
|
|
|
|
'org-mode
|
|
|
|
|
(lambda () (org-escape-code-in-region (point-min) (point-max)))
|
|
|
|
|
(org-unescape-code-in-string (org-element-property :value element)))
|
|
|
|
|
t))
|
|
|
|
|
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(defun org-edit-src-code (&optional code edit-buffer-name)
|
|
|
|
|
"Edit the source or example block at point.
|
2015-05-01 08:03:17 +00:00
|
|
|
|
\\<org-src-mode-map>
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
The code is copied to a separate buffer and the appropriate mode
|
2016-10-15 15:36:47 +00:00
|
|
|
|
is turned on. When done, exit with `\\[org-edit-src-exit]'. This \
|
2015-05-01 08:03:17 +00:00
|
|
|
|
will remove the
|
|
|
|
|
original code in the Org buffer, and replace it with the edited
|
|
|
|
|
version. See `org-src-window-setup' to configure the display of
|
|
|
|
|
windows containing the Org buffer and the code buffer.
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
|
|
|
|
When optional argument CODE is a string, edit it in a dedicated
|
|
|
|
|
buffer instead.
|
|
|
|
|
|
|
|
|
|
When optional argument EDIT-BUFFER-NAME is non-nil, use it as the
|
|
|
|
|
name of the sub-editing buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let* ((element (org-element-at-point))
|
|
|
|
|
(type (org-element-type element)))
|
|
|
|
|
(unless (and (memq type '(example-block src-block))
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(org-src--on-datum-p element))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(user-error "Not in a source or example block"))
|
|
|
|
|
(let* ((lang
|
|
|
|
|
(if (eq type 'src-block) (org-element-property :language element)
|
|
|
|
|
"example"))
|
2019-04-07 07:12:40 +00:00
|
|
|
|
(lang-f (and (eq type 'src-block) (org-src-get-lang-mode lang)))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(babel-info (and (eq type 'src-block)
|
2022-10-18 15:34:18 +00:00
|
|
|
|
(org-babel-get-src-block-info 'no-eval)))
|
2014-12-09 16:26:02 +00:00
|
|
|
|
deactivate-mark)
|
2020-02-03 17:21:26 +00:00
|
|
|
|
(when (and (eq type 'src-block) (not (functionp lang-f)))
|
|
|
|
|
(error "No such language mode: %s" lang-f))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(org-src--edit-element
|
|
|
|
|
element
|
|
|
|
|
(or edit-buffer-name
|
|
|
|
|
(org-src--construct-edit-buffer-name (buffer-name) lang))
|
2024-01-05 13:32:38 +00:00
|
|
|
|
(lambda ()
|
|
|
|
|
(when lang-f (funcall lang-f))
|
|
|
|
|
(setq-local org-coderef-label-format
|
|
|
|
|
(or (org-element-property :label-fmt element)
|
|
|
|
|
org-coderef-label-format))
|
|
|
|
|
(when (eq type 'src-block)
|
|
|
|
|
(setq org-src--babel-info babel-info)))
|
2015-04-26 08:04:55 +00:00
|
|
|
|
(and (null code)
|
2017-04-29 09:45:45 +00:00
|
|
|
|
(lambda () (org-escape-code-in-region (point-min) (point-max))))
|
2015-04-26 08:04:55 +00:00
|
|
|
|
(and code (org-unescape-code-in-string code)))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
;; Finalize buffer.
|
|
|
|
|
(when (eq type 'src-block)
|
|
|
|
|
(let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang))))
|
|
|
|
|
(when (fboundp edit-prep-func)
|
|
|
|
|
(funcall edit-prep-func babel-info))))
|
|
|
|
|
t)))
|
|
|
|
|
|
2015-11-08 19:55:31 +00:00
|
|
|
|
(defun org-edit-inline-src-code ()
|
|
|
|
|
"Edit inline source code at point."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((context (org-element-context)))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(unless (and (org-element-type-p context 'inline-src-block)
|
2015-11-08 19:55:31 +00:00
|
|
|
|
(org-src--on-datum-p context))
|
|
|
|
|
(user-error "Not on inline source code"))
|
|
|
|
|
(let* ((lang (org-element-property :language context))
|
2019-04-07 07:12:40 +00:00
|
|
|
|
(lang-f (org-src-get-lang-mode lang))
|
2022-10-18 15:34:18 +00:00
|
|
|
|
(babel-info (org-babel-get-src-block-info 'no-eval))
|
2015-11-08 19:55:31 +00:00
|
|
|
|
deactivate-mark)
|
|
|
|
|
(unless (functionp lang-f) (error "No such language mode: %s" lang-f))
|
|
|
|
|
(org-src--edit-element
|
|
|
|
|
context
|
|
|
|
|
(org-src--construct-edit-buffer-name (buffer-name) lang)
|
|
|
|
|
lang-f
|
|
|
|
|
(lambda ()
|
2018-09-20 09:23:49 +00:00
|
|
|
|
;; Inline source blocks are limited to one line.
|
2015-11-08 19:55:31 +00:00
|
|
|
|
(while (re-search-forward "\n[ \t]*" nil t) (replace-match " "))
|
|
|
|
|
;; Trim contents.
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
|
(delete-region (point-min) (point))
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(skip-chars-backward " \t")
|
|
|
|
|
(delete-region (point) (point-max))))
|
|
|
|
|
;; Finalize buffer.
|
2018-05-02 21:52:35 +00:00
|
|
|
|
(setq org-src--babel-info babel-info)
|
|
|
|
|
(setq org-src--preserve-indentation t)
|
2015-11-08 19:55:31 +00:00
|
|
|
|
(let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang))))
|
|
|
|
|
(when (fboundp edit-prep-func) (funcall edit-prep-func babel-info)))
|
|
|
|
|
;; Return success.
|
|
|
|
|
t)))
|
|
|
|
|
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(defun org-edit-fixed-width-region ()
|
|
|
|
|
"Edit the fixed-width ASCII drawing at point.
|
2016-10-15 15:36:47 +00:00
|
|
|
|
\\<org-src-mode-map>
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
This must be a region where each line starts with a colon
|
|
|
|
|
followed by a space or a newline character.
|
|
|
|
|
|
|
|
|
|
A new buffer is created and the fixed-width region is copied into
|
|
|
|
|
it, and the buffer is switched into the major mode defined in
|
2016-10-15 15:36:47 +00:00
|
|
|
|
`org-edit-fixed-width-region-mode', which see.
|
|
|
|
|
|
|
|
|
|
When done, exit with `\\[org-edit-src-exit]'. The edited text \
|
|
|
|
|
will then replace
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
the area in the Org mode buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((element (org-element-at-point)))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(unless (and (org-element-type-p element 'fixed-width)
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(org-src--on-datum-p element))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(user-error "Not in a fixed-width area"))
|
|
|
|
|
(org-src--edit-element
|
|
|
|
|
element
|
|
|
|
|
(org-src--construct-edit-buffer-name (buffer-name) "Fixed Width")
|
|
|
|
|
org-edit-fixed-width-region-mode
|
2015-04-26 08:04:55 +00:00
|
|
|
|
(lambda () (while (not (eobp)) (insert ": ") (forward-line))))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
;; Return success.
|
|
|
|
|
t))
|
|
|
|
|
|
|
|
|
|
(defun org-edit-src-abort ()
|
|
|
|
|
"Abort editing of the src code and return to the Org buffer."
|
|
|
|
|
(interactive)
|
2015-04-26 08:04:55 +00:00
|
|
|
|
(let (org-src--allow-write-back) (org-edit-src-exit)))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
2021-09-30 20:07:15 +00:00
|
|
|
|
(defun org-edit-src-continue (event)
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
"Unconditionally return to buffer editing area under point.
|
2021-09-30 20:07:15 +00:00
|
|
|
|
Throw an error if there is no such buffer.
|
|
|
|
|
EVENT is passed to `mouse-set-point'."
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(interactive "e")
|
2021-09-30 20:07:15 +00:00
|
|
|
|
(mouse-set-point event)
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(let ((buf (get-char-property (point) 'edit-buffer)))
|
|
|
|
|
(if buf (org-src-switch-to-buffer buf 'continue)
|
|
|
|
|
(user-error "No sub-editing buffer for area at point"))))
|
|
|
|
|
|
|
|
|
|
(defun org-edit-src-save ()
|
|
|
|
|
"Save parent buffer with current state source-code buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(unless (org-src-edit-buffer-p) (user-error "Not in a sub-editing buffer"))
|
|
|
|
|
(set-buffer-modified-p nil)
|
2020-10-04 19:33:30 +00:00
|
|
|
|
(let ((write-back-buf (generate-new-buffer "*org-src-write-back*"))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(beg org-src--beg-marker)
|
|
|
|
|
(end org-src--end-marker)
|
|
|
|
|
(overlay org-src--overlay))
|
2020-10-04 19:33:30 +00:00
|
|
|
|
(org-src--contents-for-write-back write-back-buf)
|
2018-11-04 14:26:04 +00:00
|
|
|
|
(with-current-buffer (org-src-source-buffer)
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(undo-boundary)
|
2014-12-12 04:34:35 +00:00
|
|
|
|
(goto-char beg)
|
2015-05-01 19:14:19 +00:00
|
|
|
|
;; Temporarily disable read-only features of OVERLAY in order to
|
|
|
|
|
;; insert new contents.
|
|
|
|
|
(delete-overlay overlay)
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(let ((expecting-bol (bolp)))
|
2021-06-01 06:56:48 +00:00
|
|
|
|
(if (version< emacs-version "27.1")
|
2020-10-04 19:33:30 +00:00
|
|
|
|
(progn (delete-region beg end)
|
|
|
|
|
(insert (with-current-buffer write-back-buf (buffer-string))))
|
2021-09-29 07:22:47 +00:00
|
|
|
|
(save-restriction
|
|
|
|
|
(narrow-to-region beg end)
|
2021-10-17 06:34:10 +00:00
|
|
|
|
(org-replace-buffer-contents write-back-buf 0.1 nil)
|
2021-09-29 07:22:47 +00:00
|
|
|
|
(goto-char (point-max))))
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(when (and expecting-bol (not (bolp))) (insert "\n")))
|
2020-10-04 19:33:30 +00:00
|
|
|
|
(kill-buffer write-back-buf)
|
2015-05-01 19:14:19 +00:00
|
|
|
|
(save-buffer)
|
2017-02-17 21:29:06 +00:00
|
|
|
|
(move-overlay overlay beg (point))))
|
2017-02-18 13:56:41 +00:00
|
|
|
|
;; `write-contents-functions' requires the function to return
|
2017-02-17 21:29:06 +00:00
|
|
|
|
;; a non-nil value so that other functions are not called.
|
|
|
|
|
t)
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
|
|
|
|
|
(defun org-edit-src-exit ()
|
|
|
|
|
"Kill current sub-editing buffer and return to source buffer."
|
|
|
|
|
(interactive)
|
2021-05-16 12:10:04 +00:00
|
|
|
|
(unless (org-src-edit-buffer-p)
|
|
|
|
|
(error "Not in a sub-editing buffer"))
|
2015-04-26 08:32:20 +00:00
|
|
|
|
(let* ((beg org-src--beg-marker)
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(end org-src--end-marker)
|
2015-04-26 08:32:20 +00:00
|
|
|
|
(write-back org-src--allow-write-back)
|
|
|
|
|
(remote org-src--remote)
|
|
|
|
|
(coordinates (and (not remote)
|
|
|
|
|
(org-src--coordinates (point) 1 (point-max))))
|
2021-05-16 12:10:04 +00:00
|
|
|
|
(write-back-buf
|
|
|
|
|
(and write-back (generate-new-buffer "*org-src-write-back*"))))
|
2020-10-04 19:33:30 +00:00
|
|
|
|
(when write-back (org-src--contents-for-write-back write-back-buf))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(set-buffer-modified-p nil)
|
|
|
|
|
;; Switch to source buffer. Kill sub-editing buffer.
|
2017-06-07 22:56:24 +00:00
|
|
|
|
(let ((edit-buffer (current-buffer))
|
|
|
|
|
(source-buffer (marker-buffer beg)))
|
2021-05-16 12:10:04 +00:00
|
|
|
|
(unless source-buffer
|
|
|
|
|
(when write-back-buf (kill-buffer write-back-buf))
|
|
|
|
|
(error "Source buffer disappeared. Aborting"))
|
2017-06-07 22:56:24 +00:00
|
|
|
|
(org-src-switch-to-buffer source-buffer 'exit)
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
(kill-buffer edit-buffer))
|
|
|
|
|
;; Insert modified code. Ensure it ends with a newline character.
|
2015-04-26 08:32:20 +00:00
|
|
|
|
(org-with-wide-buffer
|
2021-05-16 12:10:04 +00:00
|
|
|
|
(when (and write-back
|
|
|
|
|
(not (equal (buffer-substring beg end)
|
2023-05-10 13:27:13 +00:00
|
|
|
|
(with-current-buffer write-back-buf
|
|
|
|
|
(buffer-string)))))
|
2015-04-26 08:32:20 +00:00
|
|
|
|
(undo-boundary)
|
|
|
|
|
(goto-char beg)
|
2015-05-02 06:37:37 +00:00
|
|
|
|
(let ((expecting-bol (bolp)))
|
2021-06-01 06:56:48 +00:00
|
|
|
|
(if (version< emacs-version "27.1")
|
2020-10-04 19:33:30 +00:00
|
|
|
|
(progn (delete-region beg end)
|
2021-05-16 12:10:04 +00:00
|
|
|
|
(insert (with-current-buffer write-back-buf
|
|
|
|
|
(buffer-string))))
|
2021-09-29 07:22:47 +00:00
|
|
|
|
(save-restriction
|
|
|
|
|
(narrow-to-region beg end)
|
2021-10-17 06:34:10 +00:00
|
|
|
|
(org-replace-buffer-contents write-back-buf 0.1 nil)
|
2021-09-29 07:22:47 +00:00
|
|
|
|
(goto-char (point-max))))
|
2021-05-16 17:13:53 +00:00
|
|
|
|
(when (and expecting-bol (not (bolp))) (insert "\n")))))
|
|
|
|
|
(when write-back-buf (kill-buffer write-back-buf))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
;; If we are to return to source buffer, put point at an
|
|
|
|
|
;; appropriate location. In particular, if block is hidden, move
|
|
|
|
|
;; to the beginning of the block opening line.
|
2015-04-26 08:32:20 +00:00
|
|
|
|
(unless remote
|
|
|
|
|
(goto-char beg)
|
|
|
|
|
(cond
|
|
|
|
|
;; Block is hidden; move at start of block.
|
2024-04-06 12:21:10 +00:00
|
|
|
|
((org-fold-folded-p nil 'block) (forward-line -1))
|
2015-04-26 08:32:20 +00:00
|
|
|
|
(write-back (org-src--goto-coordinates coordinates beg end))))
|
org-src: Unify source editing tools
* lisp/org-src.el (org-src-strip-leading-and-trailing-blanklines,
org-edit-src-force-single-line, org-edit-src-picture,
org-edit-src-from-org-mode, org-edit-src-allow-write-back-p,
org-edit-src-beg-marker, org-edit-src-end-marker,
org-edit-src-overlay, org-edit-src-block-indentation,
org-edit-src-saved-temp-window-config, org-edit-src-code-timer):
Remove variables.
(org-src--allow-write-back-p, org-src--beg-marker,
org-src--block-indentation, org-src--code-timer, org-src--end-marker,
org-src--end-marker, org-src--from-org-mode, org-src--overlay,
org-src--saved-temp-window-config, org-src--type,
org-src--babel-info): New variables.
(org-src--construct-edit-buffer-name, org-src--edit-buffer,
org-src--source-buffer, org-src--get-lang-mode, org-src--coordinates,
org-src--goto-coordinates, org-src--element-contents-area,
org-src--make-source-overlay, org-src--on-element-p,
org-src--contents-for-write-back, org-src--edit-element,
org-edit-table.el, org-edit-export-block): New functions.
(org-edit-src-find-buffer, org-src-construct-edit-buffer-name,
org-src-tangle, org-src-in-org-buffer): Remove functions.
(org-edit-src-code, org-edit-fixed-width-region, org-edit-src-abort,
org-edit-src-save): Use new functions and variables.
(org-edit-src-exit): Use new functions and variables. Change
signature.
* lisp/org.el (org-edit-special, org-indent-line, org-indent-region):
Use new functions and variables.
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Remove useless check.
(org-babel-expand-src-block): Apply signature change.
This patches resolves discrepancies between source editing tools and
globally simplifies process (auto-save feature, region
preservation...). It introduces export block editing. It also moves
internal variables and functions into an appropriate namespace and
delete some unused functions.
2014-11-22 23:31:23 +00:00
|
|
|
|
;; Clean up left-over markers and restore window configuration.
|
|
|
|
|
(set-marker beg nil)
|
2019-12-23 16:55:55 +00:00
|
|
|
|
(set-marker end nil)
|
|
|
|
|
(when org-src--saved-temp-window-config
|
|
|
|
|
(unwind-protect
|
|
|
|
|
(set-window-configuration org-src--saved-temp-window-config)
|
|
|
|
|
(setq org-src--saved-temp-window-config nil)))))
|
2010-08-17 00:55:24 +00:00
|
|
|
|
|
2009-06-07 14:27:07 +00:00
|
|
|
|
(provide 'org-src)
|
|
|
|
|
|
|
|
|
|
;;; org-src.el ends here
|