Allow indented dynamic blocks

This commit is contained in:
Carsten Dominik 2009-09-18 09:12:26 +01:00
parent 60bf447608
commit 74a59c0c00
2 changed files with 37 additions and 8 deletions

View File

@ -1,6 +1,14 @@
2009-09-18 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-sort-entries-or-items): Include the final newline.
(org-fontify-meta-lines-and-blocks): Add indented dynamic block
lines for fontification.
(org-dblock-start-re, org-dblock-end-re): Allow indentation.
(org-prepare-dblock): Store the current indentation of the BEGIN
line.
(org-update-dblock): Apply the indentation of the begin line to
the rest of the block.
(org-ctrl-c-ctrl-c): Also find indented dblock lines.
2009-09-17 Carsten Dominik <carsten.dominik@gmail.com>

View File

@ -4366,7 +4366,8 @@ will be prompted for."
beg (match-end 0)
'(font-lock-fontified t face org-meta-line))
t)
((or (member dc1 '("caption:" "label:" "orgtbl:" "tblfm:" "tblname:"))
((or (member dc1 '("begin:" "end:" "caption:" "label:"
"orgtbl:" "tblfm:" "tblname:"))
(and (match-end 4) (equal dc3 "attr")))
(add-text-properties
beg (match-end 0)
@ -8968,23 +8969,26 @@ If not found, stay at current position and return nil."
pos))
(defconst org-dblock-start-re
"^#\\+BEGIN:[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
"^[ \t]*#\\+BEGIN:[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
"Matches the startline of a dynamic block, with parameters.")
(defconst org-dblock-end-re "^#\\+END\\([: \t\r\n]\\|$\\)"
(defconst org-dblock-end-re "^[ \t]*#\\+END\\([: \t\r\n]\\|$\\)"
"Matches the end of a dynamic block.")
(defun org-create-dblock (plist)
"Create a dynamic block section, with parameters taken from PLIST.
PLIST must contain a :name entry which is used as name of the block."
(unless (bolp) (newline))
(let ((name (plist-get plist :name)))
(when (string-match "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
(end-of-line 1)
(newline))
(let ((col (current-column))
(name (plist-get plist :name)))
(insert "#+BEGIN: " name)
(while plist
(if (eq (car plist) :name)
(setq plist (cddr plist))
(insert " " (prin1-to-string (pop plist)))))
(insert "\n\n#+END:\n")
(insert "\n\n" (make-string col ?\ ) "#+END:\n")
(beginning-of-line -2)))
(defun org-prepare-dblock ()
@ -8997,6 +9001,10 @@ the property list including an extra property :name with the block name."
(name (org-no-properties (match-string 1)))
(params (append (list :name name)
(read (concat "(" (match-string 3) ")")))))
(save-excursion
(beginning-of-line 1)
(skip-chars-forward " \t")
(setq params (plist-put params :indentation-column (current-column))))
(unless (re-search-forward org-dblock-end-re nil t)
(error "Dynamic block not terminated"))
(setq params
@ -9044,11 +9052,24 @@ the correct writing function."
(line (org-current-line))
(params (org-prepare-dblock))
(name (plist-get params :name))
(indent (plist-get params :indentation-column))
(cmd (intern (concat "org-dblock-write:" name))))
(message "Updating dynamic block `%s' at line %d..." name line)
(funcall cmd params)
(message "Updating dynamic block `%s' at line %d...done" name line)
(goto-char pos))))
(goto-char pos)
(when (and indent (> indent 0))
(setq indent (make-string indent ?\ ))
(save-excursion
(org-beginning-of-dblock)
(forward-line 1)
(while (not (looking-at org-dblock-end-re))
(insert indent)
(beginning-of-line 2))
(when (looking-at org-dblock-end-re)
(and (looking-at "[ \t]+")
(replace-match ""))
(insert indent)))))))
(defun org-beginning-of-dblock ()
"Find the beginning of the dynamic block at point.
@ -15048,7 +15069,7 @@ This command does many different things, depending on context:
(if arg
(call-interactively 'org-toggle-checkbox)
(call-interactively 'org-maybe-renumber-ordered-list)))
((save-excursion (beginning-of-line 1) (looking-at "#\\+BEGIN:"))
((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
;; Dynamic block
(beginning-of-line 1)
(save-excursion (org-update-dblock)))