Re: [O] function for inserting a block
Nicolas Goaziou writes: > Hello, > > Eric Abrahamsen writes: > >> Kaushal Modi writes: > >>> I just tried it out, and it works great! >>> >>> I have a comment about >>> >>> (when (string-equal (downcase type) "example") >>> (org-escape-code-in-region s e)) >>> >>> I have never needed to escape org in example, blocks, but I *have* needed >>> to do that in org src blocks. >>> >>> Should type string be also matched with "src org"? >>> >>> Actually should the type string be matched only with "src org"? Because I >>> see the Org example blocks as blocks in HTML with no syntax >>> highlighting.. so >>> those can contain code from any language. >>> >>> Also as this is part of org and emacs, org-structure-predefined-blocks >>> deserves "SRC org" and "SRC emacs-lisp" too? :) >> >> The template really only inserts the block type, not anything specific >> like the source language or export backend. I think prompting for >> "second-level" information like that might be a little overkill. >> >> As for what should be escaped and what shouldn't, I defer to Nicolas, >> let's see what he says. > > "src" (not only with "org" language), "example" and "export", i.e., > verbatim, blocks need to be escaped. > > You should probably use something like > > (when (string-prefix-p (regexp-opt '("example" "export" "src")) type t) >...) string-prefix-p doesn't appear to work with regular expressions, so I used string-match-p. >From 1ef3404310f516d1f762501b2bb974220a61da1d Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Sat, 7 Oct 2017 13:01:14 -0700 Subject: [PATCH] New function org-insert-structure-template * lisp/org.el (org-insert-structure-template): New function for wrapping region (or element at point) in a begin/end block. (org-structure-predefined-blocks): New option holding predefined blocks, for completion. * doc/org.texi (Structure of code blocks, Easy templates): And in manual. * testing/lisp/test-org.el (test-org/insert-template): New test. --- doc/org.texi | 21 +++-- etc/ORG-NEWS | 4 lisp/org.el | 49 testing/lisp/test-org.el | 42 + 4 files changed, 110 insertions(+), 6 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index c54f2615a..6ad9d1c15 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -15242,12 +15242,13 @@ A @samp{src} block conforms to this structure: #+END_SRC @end example -Org mode's templates system (@pxref{Easy templates}) speeds up creating -@samp{src} code blocks with just three keystrokes. Do not be put-off by -having to remember the source block syntax. Org also works with other -completion systems in Emacs, some of which predate Org and have custom -domain-specific languages for defining templates. Regular use of templates -reduces errors, increases accuracy, and maintains consistency. +Do not be put off by having to remember the source block syntax. Org mode +offers two ways of speeding up the creation of src code blocks: a template +system that can create a new block with just three keystrokes, and a command +for wrapping existing text in a block (@pxref{Easy templates}). Org also +works with other completion systems in Emacs, some of which predate Org and +have custom domain-specific languages for defining templates. Regular use of +templates reduces errors, increases accuracy, and maintains consistency. @cindex source code, inline An inline code block conforms to this structure: @@ -17418,6 +17419,14 @@ Org comes with these pre-defined easy templates: More templates can added by customizing the variable @code{org-structure-template-alist}, whose docstring has additional details. +@findex org-insert-structure-template +@kindex C-c C-x w +Easy templates are ideal when writing new content, but sometimes it is +necessary to mark up existing content. For these cases, Org provides the +function @code{org-insert-structure-template}, which prompts for a block +type, and wraps either the active region or the current Org element in that +block. This command is bound to @kbd{C-c C-x w} by default. + @node Speed keys @section Speed keys @cindex speed keys diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 1076dd970..190a6b8bc 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -109,6 +109,10 @@ you should expect to see something like: #+END_EXAMPLE ** New functions +*** ~org-insert-structure-template~ + +This function can be used to wrap existing text of Org elements in +a #+BEGIN_FOO/#+END_FOO block. Bound to C-c C-x w by default. *** ~org-export-excluded-from-toc-p~ diff --git a/lisp/org.el b/lisp/org.el index 54687abc7..552dd7ec4 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -12117,6 +12117,13 @@ keywords relative to each registered export back-end." "PRIORITIES:" "SELECT_TAGS:" "SEQ_TODO:" "SETUPFILE:" "STARTUP:" "TAGS:" "TITLE:" "TODO:" "TYP_TODO:" "SELECT_TAGS:" "EXCLUDE_TAGS
Re: [O] Bug: c++ code block automatically adds comma [8.2.10 (release_8.2.10 @ c:/Users/Louis/home/bin/emacs-24.5/share/emacs/24.5/lisp/org/)]
Hello, Louis Strous writes: > When I edit a c++ code block using C-c ' and then finish the edit using > C-c ' again, then org-mode sometimes adds a comma to the code. > > Start of reproduction scenario: > > 1. Start emacs using "emacs -Q" > > 2. Execute "org-mode" to change the *scratch* buffer's major mode to > org-mode. > > 3. Add the following text to the buffer: > > #+BEGIN_SRC c++ > #+END_SRC > > > 4. Put the cursor at the beginning of the #+BEGIN_SRC line and press > "C-c > '" to start editing the code block. The "*Org Src *scratch*[ c++ ]*" > buffer is displayed. > > 5. Enter the following c++ code in the "*Org Src *scratch*[ c++ ]*" > buffer: > > if (foo) >*foo = 3; > > 6. Note the absence of a comma in front of the "*". Now press "C-c '" > again to end editing the code block. The code block in the *scratch* > buffer changes to > > #+BEGIN_SRC c++ >if (foo) > ,*foo = 3; > #+END_SRC > > Note the appearance of a comma in front of the "*". > > 7. Press "C-c '" to edit the code block again. The code displayed in > the "*Org Src *scratch*[ c++ ]*" buffer does not contain the comma: > > if (foo) >*foo = 3; > > 8. Press "C-c '" to finish the editing. The code in the *scratch* > buffer still contains the comma. > > End of reproduction scenario. See (info "(org) Literal examples"), fourth footnote Regards, -- Nicolas Goaziou
[O] Bug: c++ code block automatically adds comma [8.2.10 (release_8.2.10 @ c:/Users/Louis/home/bin/emacs-24.5/share/emacs/24.5/lisp/org/)]
When I edit a c++ code block using C-c ' and then finish the edit using C-c ' again, then org-mode sometimes adds a comma to the code. Start of reproduction scenario: 1. Start emacs using "emacs -Q" 2. Execute "org-mode" to change the *scratch* buffer's major mode to org-mode. 3. Add the following text to the buffer: #+BEGIN_SRC c++ #+END_SRC 4. Put the cursor at the beginning of the #+BEGIN_SRC line and press "C-c '" to start editing the code block. The "*Org Src *scratch*[ c++ ]*" buffer is displayed. 5. Enter the following c++ code in the "*Org Src *scratch*[ c++ ]*" buffer: if (foo) *foo = 3; 6. Note the absence of a comma in front of the "*". Now press "C-c '" again to end editing the code block. The code block in the *scratch* buffer changes to #+BEGIN_SRC c++ if (foo) ,*foo = 3; #+END_SRC Note the appearance of a comma in front of the "*". 7. Press "C-c '" to edit the code block again. The code displayed in the "*Org Src *scratch*[ c++ ]*" buffer does not contain the comma: if (foo) *foo = 3; 8. Press "C-c '" to finish the editing. The code in the *scratch* buffer still contains the comma. End of reproduction scenario. So far I have seen this behavior only when there is a * at the beginning of the line of code. I've seen it on three different systems, the one mentioned below and also Emacs : GNU Emacs 25.2.1 (x86_64-w64-mingw32) of 2017-04-24 Package: Org-mode version 8.2.10 (release_8.2.10 @ d:/Documents/emacs/share/emacs/25.2/lisp/org/) and Emacs : GNU Emacs 25.3.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.22.19) of 2017-09-15 Package: Org-mode version 8.2.10 (release_8.2.10 @ /usr/share/emacs/25.3/lisp/org/) Regards, Louis Strous Emacs : GNU Emacs 24.5.1 (i686-pc-mingw32) of 2015-04-11 on LEG570 Package: Org-mode version 8.2.10 (release_8.2.10 @ c:/Users/Louis/home/bin/emacs-24.5/share/emacs/24.5/lisp/org/) current state: == (setq org-ctrl-c-ctrl-c-hook '(org-babel-hash-at-point org-babel-execute-safely-maybe) org-tab-first-hook '(org-hide-block-toggle-maybe org-src-native-tab-command-maybe org-babel-hide-result-toggle-maybe org-babel-header-arg-expand) org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers org-cycle-hide-inline-tasks org-cycle-show-empty-lines org-optimize-window-after-visibility-change) org-agenda-before-write-hook '(org-agenda-add-entry-text) org-speed-command-hook '(org-speed-command-default-hook org-babel-speed-command-hook) org-babel-pre-tangle-hook '(save-buffer) org-occur-hook '(org-first-headline-recenter) org-metaup-hook '(org-babel-load-in-session-maybe) org-confirm-elisp-link-function 'yes-or-no-p org-clock-out-hook '(org-clock-remove-empty-clock-drawer) org-mode-hook '(#[nil "\300\301\302\303\304$\207" [org-add-hook change-major-mode-hook org-show-block-all append local] 5] #[nil "\300\301\302\303\304$\207" [org-add-hook change-major-mode-hook org-babel-show-result-all append local] 5] org-babel-result-hide-spec org-babel-hide-all-hashes) org-metadown-hook '(org-babel-pop-to-session-maybe) org-src-mode-hook '(org-src-babel-configure-edit-buffer org-src-mode-configure-edit-buffer) org-after-todo-state-change-hook '(org-clock-out-if-current) org-confirm-shell-link-function 'yes-or-no-p )
Re: [O] Bug: Plus signs in org tables are highlighted incorrectly [9.0.9 (9.0.9-82-gb862c2-elpa @ /Users/ryan/.emacs.d/elpa/org-20170814/)]
Hello, Ryan writes: > The following table is highlighted incorrectly by org-mode: > > | Col1 | Col2 | > |--+--| > | +1 | +2 | > |--+--| > > The region of text starting at the plus sign in "+1" and ending with the > plus sign in the following divider line is covered with a strikethrough > effect. I think any font effects (bold, italic, strikethrough, etc.) > should be limited to within a single cell. Fixed. Thank you. Regards, -- Nicolas Goaziou
Re: [O] Tangling org file with nested org source block
Hello, Thibault Marin writes: > From 6300856f8b9623b1ac0a40b7fe62751805159558 Mon Sep 17 00:00:00 2001 > From: thibault > Date: Fri, 20 Oct 2017 22:20:35 -0500 > Subject: [PATCH] ob-tangle.el: Fix tangling of org block with nested source > block It looks good. Applied. Thank you. Regards, -- Nicolas Goaziou
Re: [O] function for inserting a block
Hello, Eric Abrahamsen writes: > Kaushal Modi writes: >> I just tried it out, and it works great! >> >> I have a comment about >> >> (when (string-equal (downcase type) "example") >> (org-escape-code-in-region s e)) >> >> I have never needed to escape org in example, blocks, but I *have* needed to >> do that in org src blocks. >> >> Should type string be also matched with "src org"? >> >> Actually should the type string be matched only with "src org"? Because I >> see the Org example blocks as blocks in HTML with no syntax >> highlighting.. so >> those can contain code from any language. >> >> Also as this is part of org and emacs, org-structure-predefined-blocks >> deserves "SRC org" and "SRC emacs-lisp" too? :) > > The template really only inserts the block type, not anything specific > like the source language or export backend. I think prompting for > "second-level" information like that might be a little overkill. > > As for what should be escaped and what shouldn't, I defer to Nicolas, > let's see what he says. "src" (not only with "org" language), "example" and "export", i.e., verbatim, blocks need to be escaped. You should probably use something like (when (string-prefix-p (regexp-opt '("example" "export" "src")) type t) ...) Regards, -- Nicolas Goaziou