From 5d675ca8bd16f178a66c76a92870dc23b81ad4a4 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Tue, 6 May 2008 21:18:40 +0200 Subject: [PATCH 1/2] Hmmmmmmm --- doc/org.texi | 2 -- lisp/org.el | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 040c2f05c..38c913e19 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -7301,8 +7301,6 @@ All lines between these markers are exported literally #+END_LaTeX @end example - - @node Sectioning structure, , Quoting LaTeX code, LaTeX export @subsection Sectioning structure @cindex LaTeX class diff --git a/lisp/org.el b/lisp/org.el index f6fdc81cd..a35b60b1f 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7579,6 +7579,38 @@ This function can be used in a hook." "ORGTBL" "HTML:" "LaTeX:" "BEGIN:" "END:" "TBLFM" "BEGIN_EXAMPLE" "END_EXAMPLE")) +(defcustom org-structure-template-alist + '( + ("s" "#+begin_src ?\n\n#+end_src" "#+\n\n") + ("e" "#+begin_example\n?\n#+end_example" "\n?\n") + ("q" "#+begin_quote\n?\n#+end_quote" "\n?\n") + ("v" "#+begin_verse\n?\n#+end_verse" "\n?\n") + ("l" "#+begin_latex\n?\n#+end_latex" "\n?\n") + ("L" "#+latex: " "?") + ("h" "#+begin_html\n?\n#+end_html" "\n?\n") + ("H" "#+html: " "?") + ("a" "#+begin_ascii\n?\n#+end_ascii") + ("A" "#+ascii: ") + ("i" "#+include: " "") + ) + "FIXME" + :group 'org ;????????????????? + :type 'sexp) + +(defun org-complete-expand-structure-template (start cell) + (let ((rpl (cdr cell))) + (delete-region start (point)) + (when (string-match "\\`#\\+" rpl) + (cond + ((bolp)) + ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point)))) + (delete-region (point-at-bol) (point))) + (t (newline)))) + (setq start (point)) + (insert rpl) + (if (re-search-backward "\\?" start t) (delete-char 1)))) + + (defun org-complete (&optional arg) "Perform completion on word at point. At the beginning of a headline, this completes TODO keywords as given in @@ -7593,7 +7625,8 @@ At all other locations, this simply calls the value of (interactive "P") (org-without-partial-completion (catch 'exit - (let* ((end (point)) + (let* ((a nil) + (end (point)) (beg1 (save-excursion (skip-chars-backward (org-re "[:alnum:]_@")) (point))) @@ -7602,6 +7635,12 @@ At all other locations, this simply calls the value of (point))) (confirm (lambda (x) (stringp (car x)))) (searchhead (equal (char-before beg) ?*)) + (struct + (when (and (equal (char-before beg1) ?.) + (setq a (assoc (buffer-substring beg1 (point)) + org-structure-template-alist))) + (org-complete-expand-structure-template (1- beg1) a) + (throw 'exit t))) (tag (and (equal (char-before beg1) ?:) (equal (char-after (point-at-bol)) ?*))) (prop (and (equal (char-before beg1) ?:) From ed25bd08faeb4ebe23b96fd6c4d53aadcf8fbb62 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Wed, 7 May 2008 14:18:15 +0200 Subject: [PATCH 2/2] Implement completion for some export structure elements. This is an experimental feature and does not really fit into Org, so it may go away in the future. --- ChangeLog | 6 ++++++ lisp/org-exp.el | 4 ++-- lisp/org.el | 41 ++++++++++++++++++++++++++++------------- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7010d169f..3378972bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-05-07 Carsten Dominik + + * lisp/org.el (org-complete-expand-structure-template): New, + experimental function. + (org-structure-template-alist): New, experimental option. + (org-complete): Call `org-complete-expand-structure-template'. 2008-05-06 Bastien Guerry diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 22888116f..4721029bd 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -2350,7 +2350,7 @@ PUB-DIR is set, use this as the publishing directory." table-buffer table-orig-buffer ind item-type starter didclose rpl path desc descp desc1 desc2 link - snumber fnc + snumber fnc item-tag ) (let ((inhibit-read-only t)) @@ -2760,7 +2760,7 @@ lang=\"%s\" xml:lang=\"%s\"> starter (if (match-beginning 2) (substring (match-string 2 line) 0 -1)) line (substring line (match-beginning 5)) - item-tag) + item-tag nil) (if (string-match "\\(.*?\\) ::[ \t]*" line) (setq item-type "d" item-tag (match-string 1 line) diff --git a/lisp/org.el b/lisp/org.el index a35b60b1f..504957324 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7581,24 +7581,31 @@ This function can be used in a hook." (defcustom org-structure-template-alist '( - ("s" "#+begin_src ?\n\n#+end_src" "#+\n\n") - ("e" "#+begin_example\n?\n#+end_example" "\n?\n") - ("q" "#+begin_quote\n?\n#+end_quote" "\n?\n") - ("v" "#+begin_verse\n?\n#+end_verse" "\n?\n") - ("l" "#+begin_latex\n?\n#+end_latex" "\n?\n") - ("L" "#+latex: " "?") - ("h" "#+begin_html\n?\n#+end_html" "\n?\n") - ("H" "#+html: " "?") + ("s" "#+begin_src ?\n\n#+end_src") + ("e" "#+begin_example\n?\n#+end_example") + ("q" "#+begin_quote\n?\n#+end_quote") + ("v" "#+begin_verse\n?\n#+end_verse") + ("l" "#+begin_latex\n?\n#+end_latex") + ("L" "#+latex: ") + ("h" "#+begin_html\n?\n#+end_html") + ("H" "#+html: ") ("a" "#+begin_ascii\n?\n#+end_ascii") ("A" "#+ascii: ") - ("i" "#+include: " "") + ("i" "#+include: %file ?") ) - "FIXME" - :group 'org ;????????????????? - :type 'sexp) + "Structure completion elements. +This is a list of abbreviation keys and values. The value gets inserted +it you type @samp{.} followed by the key and then the completion key, +usually `M-TAB'. %file will be replaced by a file name after prompting +for the file uning completion. +This is an experimental feature, it is undecided if it is going to stay in." + :group 'org-completion + :type '(repeat + (string :tag "Key") (string :tag "Template"))) (defun org-complete-expand-structure-template (start cell) - (let ((rpl (cdr cell))) + "Expand a structure template." + (let ((rpl (nth 1 cell))) (delete-region start (point)) (when (string-match "\\`#\\+" rpl) (cond @@ -7607,6 +7614,14 @@ This function can be used in a hook." (delete-region (point-at-bol) (point))) (t (newline)))) (setq start (point)) + (if (string-match "%file" rpl) + (setq rpl (replace-match + (concat + "\"" + (save-match-data + (abbreviate-file-name (read-file-name "Include file: "))) + "\"") + t t rpl))) (insert rpl) (if (re-search-backward "\\?" start t) (delete-char 1))))