forked from mirrors/org-mode
org-src.el: Fix special editing of LaTeX fragments
* lisp/org-macs.el (org-do-remove-indentation): Add optional argument to skip the first line. * lisp/org-src.el (org-src--coordinates): Fix coordinates for inline LaTeX fragments. (org-src--contents-for-write-back): Do not indent first line for LaTeX fragments. (org-src--edit-element): Compute block-indentation according to parent for LaTeX fragments. Skip first line when removing common indentation for LaTeX fragments.
This commit is contained in:
parent
73875939a8
commit
e1c49af76d
|
@ -326,17 +326,19 @@ it for output."
|
||||||
|
|
||||||
;;; Indentation
|
;;; Indentation
|
||||||
|
|
||||||
(defun org-do-remove-indentation (&optional n)
|
(defun org-do-remove-indentation (&optional n skip-fl)
|
||||||
"Remove the maximum common indentation from the buffer.
|
"Remove the maximum common indentation from the buffer.
|
||||||
When optional argument N is a positive integer, remove exactly
|
When optional argument N is a positive integer, remove exactly
|
||||||
that much characters from indentation, if possible. Return nil
|
that much characters from indentation, if possible. When
|
||||||
if it fails."
|
optional argument SKIP-FL is non-nil, skip the first
|
||||||
|
line. Return nil if it fails."
|
||||||
(catch :exit
|
(catch :exit
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
;; Find maximum common indentation, if not specified.
|
;; Find maximum common indentation, if not specified.
|
||||||
(let ((n (or n
|
(let ((n (or n
|
||||||
(let ((min-ind (point-max)))
|
(let ((min-ind (point-max)))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
|
(when skip-fl (forward-line))
|
||||||
(while (re-search-forward "^[ \t]*\\S-" nil t)
|
(while (re-search-forward "^[ \t]*\\S-" nil t)
|
||||||
(let ((ind (current-indentation)))
|
(let ((ind (current-indentation)))
|
||||||
(if (zerop ind) (throw :exit nil)
|
(if (zerop ind) (throw :exit nil)
|
||||||
|
@ -344,6 +346,7 @@ if it fails."
|
||||||
min-ind))))
|
min-ind))))
|
||||||
(if (zerop n) (throw :exit nil)
|
(if (zerop n) (throw :exit nil)
|
||||||
;; Remove exactly N indentation, but give up if not possible.
|
;; Remove exactly N indentation, but give up if not possible.
|
||||||
|
(when skip-fl (forward-line))
|
||||||
(while (not (eobp))
|
(while (not (eobp))
|
||||||
(let ((ind (progn (skip-chars-forward " \t") (current-column))))
|
(let ((ind (progn (skip-chars-forward " \t") (current-column))))
|
||||||
(cond ((eolp) (delete-region (line-beginning-position) (point)))
|
(cond ((eolp) (delete-region (line-beginning-position) (point)))
|
||||||
|
|
|
@ -327,7 +327,8 @@ a cons cell (LINE . COLUMN) or symbol `end'. See also
|
||||||
(if (>= pos end) 'end
|
(if (>= pos end) 'end
|
||||||
(org-with-wide-buffer
|
(org-with-wide-buffer
|
||||||
(goto-char (max beg pos))
|
(goto-char (max beg pos))
|
||||||
(cons (count-lines beg (line-beginning-position))
|
(cons (count-lines (save-excursion (goto-char beg) (line-beginning-position))
|
||||||
|
(line-beginning-position))
|
||||||
;; Column is relative to the end of line to avoid problems of
|
;; Column is relative to the end of line to avoid problems of
|
||||||
;; comma escaping or colons appended in front of the line.
|
;; comma escaping or colons appended in front of the line.
|
||||||
(- (point) (min end (line-end-position)))))))
|
(- (point) (min end (line-end-position)))))))
|
||||||
|
@ -445,6 +446,7 @@ Assume point is in the corresponding edit buffer."
|
||||||
org-src--content-indentation
|
org-src--content-indentation
|
||||||
0))))
|
0))))
|
||||||
(use-tabs? (and (> org-src--tab-width 0) t))
|
(use-tabs? (and (> org-src--tab-width 0) t))
|
||||||
|
(preserve-fl (eq org-src--source-type 'latex-fragment))
|
||||||
(source-tab-width org-src--tab-width)
|
(source-tab-width org-src--tab-width)
|
||||||
(contents (org-with-wide-buffer
|
(contents (org-with-wide-buffer
|
||||||
(let ((eol (line-end-position)))
|
(let ((eol (line-end-position)))
|
||||||
|
@ -466,7 +468,8 @@ Assume point is in the corresponding edit buffer."
|
||||||
;; Add INDENTATION-OFFSET to every line in buffer,
|
;; Add INDENTATION-OFFSET to every line in buffer,
|
||||||
;; unless indentation is meant to be preserved.
|
;; unless indentation is meant to be preserved.
|
||||||
(when (> indentation-offset 0)
|
(when (> indentation-offset 0)
|
||||||
(while (not (eobp))
|
(when preserve-fl (forward-line))
|
||||||
|
(while (not (eobp))
|
||||||
(skip-chars-forward " \t")
|
(skip-chars-forward " \t")
|
||||||
(when (or (not (eolp)) ; not a blank line
|
(when (or (not (eolp)) ; not a blank line
|
||||||
(and (eq (point) (marker-position marker)) ; current line
|
(and (eq (point) (marker-position marker)) ; current line
|
||||||
|
@ -518,7 +521,13 @@ Leave point in edit buffer."
|
||||||
(source-tab-width (if indent-tabs-mode tab-width 0))
|
(source-tab-width (if indent-tabs-mode tab-width 0))
|
||||||
(type (org-element-type datum))
|
(type (org-element-type datum))
|
||||||
(block-ind (org-with-point-at (org-element-property :begin datum)
|
(block-ind (org-with-point-at (org-element-property :begin datum)
|
||||||
(current-indentation)))
|
(cond
|
||||||
|
((save-excursion (skip-chars-backward " \t") (bolp))
|
||||||
|
(current-indentation))
|
||||||
|
((org-element-property :parent datum)
|
||||||
|
(org--get-expected-indentation
|
||||||
|
(org-element-property :parent datum) nil))
|
||||||
|
(t (current-indentation)))))
|
||||||
(content-ind org-edit-src-content-indentation)
|
(content-ind org-edit-src-content-indentation)
|
||||||
(blank-line (save-excursion (beginning-of-line)
|
(blank-line (save-excursion (beginning-of-line)
|
||||||
(looking-at-p "^[[:space:]]*$")))
|
(looking-at-p "^[[:space:]]*$")))
|
||||||
|
@ -548,7 +557,8 @@ Leave point in edit buffer."
|
||||||
(insert contents)
|
(insert contents)
|
||||||
(remove-text-properties (point-min) (point-max)
|
(remove-text-properties (point-min) (point-max)
|
||||||
'(display nil invisible nil intangible nil))
|
'(display nil invisible nil intangible nil))
|
||||||
(unless preserve-ind (org-do-remove-indentation))
|
(let ((lf (eq type 'latex-fragment)))
|
||||||
|
(unless preserve-ind (org-do-remove-indentation (and lf block-ind) lf)))
|
||||||
(set-buffer-modified-p nil)
|
(set-buffer-modified-p nil)
|
||||||
(setq buffer-file-name nil)
|
(setq buffer-file-name nil)
|
||||||
;; Initialize buffer.
|
;; Initialize buffer.
|
||||||
|
|
Loading…
Reference in a new issue