1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-26 07:33:39 +00:00

Blocks: Make editing indented blocks work correctly

This commit is contained in:
Carsten Dominik 2009-05-26 07:35:40 +02:00
parent 0b60bf8aac
commit 1fc138838a
3 changed files with 43 additions and 22 deletions

View File

@ -1,3 +1,13 @@
2009-05-26 Carsten Dominik <carsten.dominik@gmail.com>
* org-exp.el (org-export-format-source-code-or-example): Make
editing indented blocks work correctly.
* org.el (org-edit-src-nindent): New variable.
(org-edit-src-code, org-edit-fixed-width-region)
(org-edit-src-find-region-and-lang, org-edit-src-exit): Make
editing indented blocks work correctly.
2009-05-24 Carsten Dominik <carsten.dominik@gmail.com>
* org-exp.el (org-export-replace-src-segments-and-examples): FInd

View File

@ -2170,13 +2170,16 @@ Numbering lines works for all three major backends (html, latex, and ascii)."
(setq num nil cont nil lang nil))
(if keepp (setq rpllbl 'keep))
(setq rtn (org-remove-indentation code))
(when (equal lang "org")
(when (string-match "^," rtn)
(setq rtn (with-temp-buffer
(insert rtn)
;; Free up the protected lines
(goto-char (point-min))
(while (re-search-forward "^," nil t)
(replace-match "")
(if (or (equal lang "org")
(save-match-data
(looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
(replace-match ""))
(end-of-line 1))
(buffer-string))))
;; Now backend-specific coding

View File

@ -6460,6 +6460,7 @@ If WITH-CASE is non-nil, the sorting will be case-sensitive."
(defvar org-edit-src-beg-marker nil)
(defvar org-edit-src-end-marker nil)
(defvar org-edit-src-overlay nil)
(defvar org-edit-src-nindent nil)
(define-minor-mode org-exit-edit-mode
"Minor mode installing a single key binding, \"C-c '\" to exit special edit.")
@ -6479,7 +6480,7 @@ the edited version."
(org-mode-p (eq major-mode 'org-mode))
(beg (make-marker))
(end (make-marker))
ovl lang lang-f single lfmt code begline buffer)
nindent ovl lang lang-f single lfmt code begline buffer)
(if (not info)
nil
(setq beg (move-marker beg (nth 0 info))
@ -6517,6 +6518,7 @@ the edited version."
(insert code)
(remove-text-properties (point-min) (point-max)
'(display nil invisible nil intangible nil))
(setq nindent (org-do-remove-indentation))
(let ((org-inhibit-startup t))
(funcall lang-f))
(set (make-local-variable 'org-edit-src-force-single-line) single)
@ -6532,6 +6534,7 @@ the edited version."
(org-set-local 'org-edit-src-beg-marker beg)
(org-set-local 'org-edit-src-end-marker end)
(org-set-local 'org-edit-src-overlay ovl)
(org-set-local 'org-edit-src-nindent nindent)
(and org-edit-src-persistent-message
(org-set-local 'header-line-format msg)))
(message "%s" msg)
@ -6575,7 +6578,7 @@ the fragment in the Org-mode buffer."
(org-mode-p (eq major-mode 'org-mode))
(beg (make-marker))
(end (make-marker))
ovl beg1 end1 code begline buffer)
nindent ovl beg1 end1 code begline buffer)
(beginning-of-line 1)
(if (looking-at "[ \t]*[^:\n \t]")
nil
@ -6618,6 +6621,7 @@ the fragment in the Org-mode buffer."
(insert code)
(remove-text-properties (point-min) (point-max)
'(display nil invisible nil intangible nil))
(setq nindent (org-do-remove-indentation))
(cond
((eq org-edit-fixed-width-region-mode 'artist-mode)
(fundamental-mode)
@ -6634,6 +6638,7 @@ the fragment in the Org-mode buffer."
(org-set-local 'org-edit-src-beg-marker beg)
(org-set-local 'org-edit-src-end-marker end)
(org-set-local 'org-edit-src-overlay ovl)
(org-set-local 'org-edit-src-nindent nindent)
(and org-edit-src-persistent-message
(org-set-local 'header-line-format msg)))
(message "%s" msg)
@ -6654,14 +6659,16 @@ the language, a switch telling of the content should be in a single line."
("<perl>[ \t]*\n?" "\n?[ \t]*</perl>" "perl")
("<python>[ \t]*\n?" "\n?[ \t]*</python>" "python")
("<ruby>[ \t]*\n?" "\n?[ \t]*</ruby>" "ruby")
("^#\\+begin_src\\( \\([^ \t\n]+\\)\\)?.*\n" "\n#\\+end_src" 2)
("^#\\+begin_example.*\n" "\n#\\+end_example" "fundamental")
("^#\\+html:" "\n" "html" single-line)
("^#\\+begin_html.*\n" "\n#\\+end_html" "html")
("^#\\+begin_latex.*\n" "\n#\\+end_latex" "latex")
("^#\\+latex:" "\n" "latex" single-line)
("^#\\+begin_ascii.*\n" "\n#\\+end_ascii" "fundamental")
("^#\\+ascii:" "\n" "ascii" single-line)
("^[ \t]*#\\+begin_src\\( \\([^ \t\n]+\\)\\)?.*\n" "\n[ \t]*#\\+end_src" 2)
("^[ \t]*#\\+begin_example.*\n" "\n[ \t]*#\\+end_example" "fundamental")
("^[ \t]*#\\+html:" "\n" "html" single-line)
("^[ \t]*#\\+begin_html.*\n" "\n[ \t]*#\\+end_html" "html")
("^[ \t]*#\\+latex:" "\n" "latex" single-line)
("^[ \t]*#\\+begin_latex.*\n" "\n[ \t]*#\\+end_latex" "latex")
("^[ \t]*#\\+ascii:" "\n" "fundamental" single-line)
("^[ \t]*#\\+begin_ascii.*\n" "\n[ \t]*#\\+end_ascii" "fundamental")
("^[ \t]*#\\+docbook:" "\n" "xml" single-line)
("^[ \t]*#\\+begin_docbook.*\n" "\n[ \t]*#\\+end_docbook" "xml")
)))
(pos (point))
re1 re2 single beg end lang lfmt match-re1)
@ -6727,6 +6734,7 @@ the language, a switch telling of the content should be in a single line."
(end org-edit-src-end-marker)
(ovl org-edit-src-overlay)
(buffer (current-buffer))
(nindent org-edit-src-nindent)
code)
(goto-char (point-min))
(if (looking-at "[ \t\n]*\n") (replace-match ""))
@ -6741,19 +6749,19 @@ the language, a switch telling of the content should be in a single line."
(replace-match "")))
(when (org-bound-and-true-p org-edit-src-from-org-mode)
(goto-char (point-min))
(while (re-search-forward (if (org-mode-p) "^\\(.\\)" "^\\([*#]\\)") nil t)
(replace-match ",\\1"))
(when font-lock-mode
(font-lock-unfontify-region (point-min) (point-max)))
(put-text-property (point-min) (point-max) 'font-lock-fontified t))
(while (re-search-forward
(if (org-mode-p) "^\\(.\\)" "^\\([*#]\\|[ \t]*#\\+\\)") nil t)
(replace-match ",\\1")))
(when (org-bound-and-true-p org-edit-src-picture)
(untabify (point-min) (point-max))
(goto-char (point-min))
(while (re-search-forward "^" nil t)
(replace-match ": "))
(when font-lock-mode
(font-lock-unfontify-region (point-min) (point-max)))
(put-text-property (point-min) (point-max) 'font-lock-fontified t))
(replace-match ": ")))
(when nindent
(setq nindent (make-string nindent ?\ ))
(goto-char (point-min))
(while (re-search-forward "^" nil t)
(replace-match nindent)))
(setq code (buffer-string))
(switch-to-buffer (marker-buffer beg))
(kill-buffer buffer)
@ -15479,7 +15487,7 @@ N may optionally be the number of spaces to remove."
(while (re-search-forward re nil t)
(replace-match "")
(end-of-line 1))
n)))
min)))
(defun org-base-buffer (buffer)
"Return the base buffer of BUFFER, if it has one. Else return the buffer."