forked from mirrors/org-mode
Fix indentation of drawers, blocks and literal examples
* lisp/org.el (org-indent-line-function): drawers and blocks have no influence on indentation of text below. Also fix indentation problem with a block at column 0 and add a special case for literal examples.
This commit is contained in:
parent
97f4c3f9a1
commit
c538b0eeab
31
lisp/org.el
31
lisp/org.el
|
@ -18671,7 +18671,7 @@ which make use of the date at the cursor."
|
||||||
;; We want this to be just right, so use the full arsenal.
|
;; We want this to be just right, so use the full arsenal.
|
||||||
|
|
||||||
(defun org-indent-line-function ()
|
(defun org-indent-line-function ()
|
||||||
"Indent line like previous, but further if previous was headline or item."
|
"Indent line depending on context."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((pos (point))
|
(let* ((pos (point))
|
||||||
(itemp (org-at-item-p))
|
(itemp (org-at-item-p))
|
||||||
|
@ -18680,13 +18680,15 @@ which make use of the date at the cursor."
|
||||||
(inline-task-p (and (featurep 'org-inlinetask)
|
(inline-task-p (and (featurep 'org-inlinetask)
|
||||||
(org-inlinetask-in-task-p)))
|
(org-inlinetask-in-task-p)))
|
||||||
column bpos bcol tpos tcol)
|
column bpos bcol tpos tcol)
|
||||||
;; Find the previous relevant line
|
|
||||||
(beginning-of-line 1)
|
(beginning-of-line 1)
|
||||||
(cond
|
(cond
|
||||||
;; Comments
|
;; Comments
|
||||||
((looking-at "# ") (setq column 0))
|
((looking-at "# ") (setq column 0))
|
||||||
;; Headings
|
;; Headings
|
||||||
((looking-at "\\*+ ") (setq column 0))
|
((looking-at "\\*+ ") (setq column 0))
|
||||||
|
;; Literal examples
|
||||||
|
((looking-at "[ \t]*:[ \t]")
|
||||||
|
(setq column (org-get-indentation))) ; do nothing
|
||||||
;; Drawers
|
;; Drawers
|
||||||
((and (looking-at "[ \t]*:END:")
|
((and (looking-at "[ \t]*:END:")
|
||||||
(save-excursion (re-search-backward org-drawer-regexp nil t)))
|
(save-excursion (re-search-backward org-drawer-regexp nil t)))
|
||||||
|
@ -18719,20 +18721,23 @@ which make use of the date at the cursor."
|
||||||
(setq tcol (+ bcol 5)))
|
(setq tcol (+ bcol 5)))
|
||||||
(goto-char pos)
|
(goto-char pos)
|
||||||
(setq column (if itemp (org-get-indentation) tcol)))
|
(setq column (if itemp (org-get-indentation) tcol)))
|
||||||
;; This line has nothing special, look upside to get a clue about
|
;; This line has nothing special, look at the previous relevant
|
||||||
;; what to do.
|
;; line to compute indentation
|
||||||
(t
|
(t
|
||||||
(beginning-of-line 0)
|
(beginning-of-line 0)
|
||||||
(while (and (not (bobp))
|
(while (and (not (bobp))
|
||||||
|
(not (looking-at org-drawer-regexp))
|
||||||
;; skip comments, verbatim, empty lines, tables,
|
;; skip comments, verbatim, empty lines, tables,
|
||||||
;; inline tasks
|
;; inline tasks, lists, drawers and blocks
|
||||||
(or (looking-at "[ \t]*[\n:#|]")
|
(or (and (looking-at "[ \t]*:END:")
|
||||||
|
(re-search-backward org-drawer-regexp nil t))
|
||||||
|
(and (looking-at "[ \t]*#\\+end_")
|
||||||
|
(re-search-backward "[ \t]*#\\+begin_"nil t))
|
||||||
|
(looking-at "[ \t]*[\n:#|]")
|
||||||
(and (org-in-item-p) (goto-char (org-list-top-point)))
|
(and (org-in-item-p) (goto-char (org-list-top-point)))
|
||||||
(and (not inline-task-p)
|
(and (not inline-task-p)
|
||||||
(featurep 'org-inlinetask)
|
(featurep 'org-inlinetask)
|
||||||
(org-inlinetask-in-task-p)))
|
(org-inlinetask-in-task-p))))
|
||||||
(not (looking-at "[ \t]*:END:"))
|
|
||||||
(not (looking-at org-drawer-regexp)))
|
|
||||||
(beginning-of-line 0))
|
(beginning-of-line 0))
|
||||||
(cond
|
(cond
|
||||||
;; There was an heading above.
|
;; There was an heading above.
|
||||||
|
@ -18741,20 +18746,18 @@ which make use of the date at the cursor."
|
||||||
(setq column 0)
|
(setq column 0)
|
||||||
(goto-char (match-end 0))
|
(goto-char (match-end 0))
|
||||||
(setq column (current-column))))
|
(setq column (current-column))))
|
||||||
;; A drawer had started and is unfinished: indent consequently.
|
;; A drawer had started and is unfinished
|
||||||
((looking-at org-drawer-regexp)
|
((looking-at org-drawer-regexp)
|
||||||
(goto-char (1- (match-beginning 1)))
|
(goto-char (1- (match-beginning 1)))
|
||||||
(setq column (current-column)))
|
(setq column (current-column)))
|
||||||
;; The drawer had ended: indent like its :END: line.
|
|
||||||
((looking-at "\\([ \t]*\\):END:")
|
|
||||||
(goto-char (match-end 1))
|
|
||||||
(setq column (current-column)))
|
|
||||||
;; Else, nothing noticeable found: get indentation and go on.
|
;; Else, nothing noticeable found: get indentation and go on.
|
||||||
(t (setq column (org-get-indentation))))))
|
(t (setq column (org-get-indentation))))))
|
||||||
|
;; Now apply indentation and move cursor accordingly
|
||||||
(goto-char pos)
|
(goto-char pos)
|
||||||
(if (<= (current-column) (current-indentation))
|
(if (<= (current-column) (current-indentation))
|
||||||
(org-indent-line-to column)
|
(org-indent-line-to column)
|
||||||
(save-excursion (org-indent-line-to column)))
|
(save-excursion (org-indent-line-to column)))
|
||||||
|
;; Special polishing for properties, see `org-property-format'
|
||||||
(setq column (current-column))
|
(setq column (current-column))
|
||||||
(beginning-of-line 1)
|
(beginning-of-line 1)
|
||||||
(if (looking-at
|
(if (looking-at
|
||||||
|
|
Loading…
Reference in New Issue