* Indenting source code blocks in lists @ 2012-01-25 6:03 Jarmo Hurri 2012-01-25 6:46 ` Bastien ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: Jarmo Hurri @ 2012-01-25 6:03 UTC (permalink / raw) To: emacs-orgmode Greetings. I am a big fan of org mode, but occasionally I feel that it is quite difficult to figure out how to do a relatively simple task. So sorry for this newbie question. The manual clearly states the following: "Since indentation is what governs the structure of these lists, many structural constructs like #+BEGIN_... blocks can be indented to signal that they belong to a particular item. " Ok. By searching in Emacs for different commands containing "indent" I was able to find out that pressing C-j in a list item indents the next line so that a subsequently written source block would also be indented. But let us assume that I already have a source block, and it is not indented correctly; what is the easy way to indent this block in a list? (I can always keep pressing spacebar, but it does not feel very intelligent.) -- Jarmo ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Indenting source code blocks in lists 2012-01-25 6:03 Indenting source code blocks in lists Jarmo Hurri @ 2012-01-25 6:46 ` Bastien 2012-01-25 12:09 ` Nicolas Goaziou 2012-01-25 9:42 ` Phil (Philip) Mason 2012-01-25 10:12 ` Jambunathan K 2 siblings, 1 reply; 7+ messages in thread From: Bastien @ 2012-01-25 6:46 UTC (permalink / raw) To: Jarmo Hurri; +Cc: emacs-orgmode Hi Jarmo, Jarmo Hurri <jarmo.hurri@syk.fi> writes: > But let us assume that I already have a source block, and it is not > indented correctly; what is the easy way to indent this block in a list? > (I can always keep pressing spacebar, but it does not feel very > intelligent.) I select the region, then `C-x r t' to insert the whitespaces. But I don't feel very clever neither, we should have a better way for this -- something that deactivate folding and indent to the beginning of the list item above. -- Bastien ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Indenting source code blocks in lists 2012-01-25 6:46 ` Bastien @ 2012-01-25 12:09 ` Nicolas Goaziou 2012-01-25 14:37 ` Bastien 0 siblings, 1 reply; 7+ messages in thread From: Nicolas Goaziou @ 2012-01-25 12:09 UTC (permalink / raw) To: Bastien; +Cc: Jarmo Hurri, emacs-orgmode Hello, Bastien <bzg@altern.org> writes: > Jarmo Hurri <jarmo.hurri@syk.fi> writes: >> But let us assume that I already have a source block, and it is not >> indented correctly; what is the easy way to indent this block in a list? >> (I can always keep pressing spacebar, but it does not feel very >> intelligent.) > I select the region, then `C-x r t' to insert the whitespaces. I use C-x r o, which doesn't require to count the spaces, and is more visual. > But I don't feel very clever neither, we should have a better > way for this -- something that deactivate folding and indent > to the beginning of the list item above. I'm not sure we should provide this. There are already so many ways, often in muscle memory, to achieve the same in Emacs that we probably shouldn't bother. Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Indenting source code blocks in lists 2012-01-25 12:09 ` Nicolas Goaziou @ 2012-01-25 14:37 ` Bastien 2012-01-28 23:56 ` Bastien 0 siblings, 1 reply; 7+ messages in thread From: Bastien @ 2012-01-25 14:37 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: Jarmo Hurri, emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 910 bytes --] Nicolas Goaziou <n.goaziou@gmail.com> writes: >> I select the region, then `C-x r t' to insert the whitespaces. > > I use C-x r o, which doesn't require to count the spaces, and is more > visual. Clever -- I start to love this mailing list ;) >> But I don't feel very clever neither, we should have a better >> way for this -- something that deactivate folding and indent >> to the beginning of the list item above. > > I'm not sure we should provide this. There are already so many ways, > often in muscle memory, to achieve the same in Emacs that we probably > shouldn't bother. The attached patch let `org-metaright' indent a drawer or a block correctly. It introduces two new function ̀org-indent-block' and `org-indent-drawer' which derive from local hacks I'm using quite often now. Perhaps ̀org-metaright' is not the best keybinding for this function, please suggest a better one. Thanks, [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-org.el-Make-org-metaright-indent-drawers-and-blocks.patch --] [-- Type: text/x-patch, Size: 3867 bytes --] From 89e8c4e37b7f2f7bbf27b31d85ff8e328046ab1b Mon Sep 17 00:00:00 2001 From: Bastien Guerry <bzg@altern.org> Date: Wed, 25 Jan 2012 15:33:45 +0100 Subject: [PATCH] org.el: Make `org-metaright' indent drawers and blocks. * org.el (org-at-drawer-p): Normalize the docstring to match other `org-at-*-p' docstrings. (org-indent-block, org-indent-drawer, org-at-block-p): New functions. (org-metaright): Use the new functions to indent a drawer or a block depending on the context. Also update the docstring. --- lisp/org.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 52 insertions(+), 3 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 61cef0a..689784d 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -17990,14 +17990,16 @@ See the individual commands for more information." (t (call-interactively 'backward-word)))) (defun org-metaright (&optional arg) - "Demote subtree or move table column to right. -Calls `org-do-demote' or `org-table-move-column', depending on context. + "Demote a subtree, a list item or move table column to right. +In front of a drawer or a block keyword, indent it correctly. With no specific context, calls the Emacs default `forward-word'. See the individual commands for more information." (interactive "P") (cond ((run-hook-with-args-until-success 'org-metaright-hook)) ((org-at-table-p) (call-interactively 'org-table-move-column)) + ((org-at-drawer-p) (call-interactively 'org-indent-drawer)) + ((org-at-block-p) (call-interactively 'org-indent-block)) ((org-with-limited-levels (or (org-at-heading-p) (and (org-region-active-p) @@ -20161,6 +20163,47 @@ If point is in an inline task, mark that task instead." t t)) (org-move-to-column column))) +(defun org-indent-drawer () + "Indent the drawer at point." + (interactive) + (let ((p (point)) + (e (and (save-excursion (re-search-forward ":END:" nil t)) + (match-end 0))) + (folded + (save-excursion + (end-of-line) + (when (overlays-at (point)) + (member 'invisible (overlay-properties + (car (overlays-at (point))))))))) + (when folded (org-cycle)) + (indent-for-tab-command) + (while (and (move-beginning-of-line 2) (< (point) e)) + (indent-for-tab-command)) + (goto-char p) + (when folded (org-cycle))) + (message "Drawer at point indented")) + +(defun org-indent-block () + "Indent the block at point." + (interactive) + (let ((p (point)) + (case-fold-search t) + (e (and (save-excursion (re-search-forward "#\\+end_?\\(?:[a-z]+\\)?" nil t)) + (match-end 0))) + (folded + (save-excursion + (end-of-line) + (when (overlays-at (point)) + (member 'invisible (overlay-properties + (car (overlays-at (point))))))))) + (when folded (org-cycle)) + (indent-for-tab-command) + (while (and (move-beginning-of-line 2) (< (point) e)) + (indent-for-tab-command)) + (goto-char p) + (when folded (org-cycle))) + (message "Block at point indented")) + (defvar org-adaptive-fill-regexp-backup adaptive-fill-regexp "Variable to store copy of `adaptive-fill-regexp'. Since `adaptive-fill-regexp' is set to never match, we need to @@ -20712,11 +20755,17 @@ This version does not only check the character property, but also (defalias 'org-on-heading-p 'org-at-heading-p) (defun org-at-drawer-p nil - "Whether point is at a drawer." + "Is cursor at a drawer keyword?" (save-excursion (move-beginning-of-line 1) (looking-at org-drawer-regexp))) +(defun org-at-block-p nil + "Is cursor at a block keyword?" + (save-excursion + (move-beginning-of-line 1) + (looking-at org-block-regexp))) + (defun org-point-at-end-of-empty-headline () "If point is at the end of an empty headline, return t, else nil. If the heading only contains a TODO keyword, it is still still considered -- 1.7.8.4 [-- Attachment #3: Type: text/plain, Size: 14 bytes --] -- Bastien ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: Indenting source code blocks in lists 2012-01-25 14:37 ` Bastien @ 2012-01-28 23:56 ` Bastien 0 siblings, 0 replies; 7+ messages in thread From: Bastien @ 2012-01-28 23:56 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: Jarmo Hurri, emacs-orgmode Bastien <bzg@altern.org> writes: > The attached patch let `org-metaright' indent a drawer or a block > correctly. It introduces two new function ̀org-indent-block' and > `org-indent-drawer' which derive from local hacks I'm using quite > often now. > > Perhaps ̀org-metaright' is not the best keybinding for this function, > please suggest a better one. I've tested this patch and just applied it. Using M-<right> on a drawer keyword (like ":PROPERTIES:") will indent the whole drawer. org-metaright looks quite natural most of the time, since the purpose is to realign the drawer with the headline/paragraph above, and statistically (?) headlines are more often refiles to subsubtrees than to trees. -- Bastien ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Indenting source code blocks in lists 2012-01-25 6:03 Indenting source code blocks in lists Jarmo Hurri 2012-01-25 6:46 ` Bastien @ 2012-01-25 9:42 ` Phil (Philip) Mason 2012-01-25 10:12 ` Jambunathan K 2 siblings, 0 replies; 7+ messages in thread From: Phil (Philip) Mason @ 2012-01-25 9:42 UTC (permalink / raw) To: emacs-orgmode@gnu.org > But let us assume that I already have a source block, and it is not > indented correctly; what is the easy way to indent this block in a list? If you indent just the #+BEGIN_SRC line and then use C-c ' to open the source editor and C-c ' to close it again it indents all source to the level of the BEGIN_SRC line. For example #+BEGIN_SRC emacs-lisp (message (number-to-string (- (point) 10)) #+END_SRC Becomes #+BEGIN_SRC emacs-lisp (message (number-to-string (- (point) 10)) #+END_SRC Is that closer to what you wanted? All the best Phil ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Indenting source code blocks in lists 2012-01-25 6:03 Indenting source code blocks in lists Jarmo Hurri 2012-01-25 6:46 ` Bastien 2012-01-25 9:42 ` Phil (Philip) Mason @ 2012-01-25 10:12 ` Jambunathan K 2 siblings, 0 replies; 7+ messages in thread From: Jambunathan K @ 2012-01-25 10:12 UTC (permalink / raw) To: Jarmo Hurri; +Cc: emacs-orgmode Jarmo Hurri <jarmo.hurri@syk.fi> writes: > what is the easy way to indent this block Mark the block as you would mark regularly. Then to 10 spaces you can do this: C-u 1 0 C-x TAB To figure out the number of spaces to add, you mentally the subtract the current column with the target column. Turn on M-x column-number-mode if you need to to figure out what column you are on. or Refer the last paragraph in: (info "(emacs) Indentation Commands") or Launch the info manual with: C-h r Visit the needed index entry with: i indent-rigidly -- ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-01-28 23:55 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-01-25 6:03 Indenting source code blocks in lists Jarmo Hurri 2012-01-25 6:46 ` Bastien 2012-01-25 12:09 ` Nicolas Goaziou 2012-01-25 14:37 ` Bastien 2012-01-28 23:56 ` Bastien 2012-01-25 9:42 ` Phil (Philip) Mason 2012-01-25 10:12 ` Jambunathan K
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).