emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Eric Abrahamsen <eric@ericabrahamsen.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: [RFC] Rewrite indentation functions
Date: Sun, 04 May 2014 21:45:15 +0200	[thread overview]
Message-ID: <87eh09pbuc.fsf@gmail.com> (raw)
In-Reply-To: <87r44ab4q2.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Sun, 04 May 2014 11:30:29 +0800")

[-- Attachment #1: Type: text/plain, Size: 140 bytes --]

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Perhaps we need a new version of patch 3?

Here it is.


Regards,

-- 
Nicolas Goaziou

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-Rewrite-org-indent-drawer-and-org-indent-block.patch --]
[-- Type: text/x-diff, Size: 3461 bytes --]

From 66d0ab7d1025969e5fd383b93ffe1fb1b05a83a8 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Mon, 28 Apr 2014 18:38:31 +0200
Subject: [PATCH 3/3] Rewrite `org-indent-drawer' and `org-indent-block'

* lisp/org.el (org-indent-block, org-indent-drawer): Rewrite functions.
---
 lisp/org.el | 75 ++++++++++++++++++++++++++++---------------------------------
 1 file changed, 34 insertions(+), 41 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index af34d99..e8d6fa9 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -22382,47 +22382,6 @@ Also align node properties according to `org-property-format'."
 		 (org--align-node-property)
 		 (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"))
-
 (defun org-indent-region (start end)
   "Indent each non-blank line in the region.
 Called from a program, START and END specify the region to
@@ -22520,6 +22479,40 @@ assumed to be significant there."
 	    (set-marker element-end nil))))
       (set-marker end nil))))
 
+(defun org-indent-drawer ()
+  "Indent the drawer at point."
+  (interactive)
+  (unless (save-excursion
+	    (beginning-of-line)
+	    (org-looking-at-p org-drawer-regexp))
+    (user-error "Not at a drawer"))
+  (let ((element (org-element-at-point)))
+    (unless (memq (org-element-type element) '(drawer property-drawer))
+      (user-error "Not at a drawer"))
+    (org-with-wide-buffer
+     (org-indent-region (org-element-property :begin element)
+			(org-element-property :end element))))
+  (message "Drawer at point indented"))
+
+(defun org-indent-block ()
+  "Indent the block at point."
+  (interactive)
+  (unless (save-excursion
+	    (beginning-of-line)
+	    (let ((case-fold-search t))
+	      (org-looking-at-p "[ \t]*#\\+\\(begin\\|end\\)_")))
+    (user-error "Not at a block"))
+  (let ((element (org-element-at-point)))
+    (unless (memq (org-element-type element)
+		  '(comment-block center-block example-block export-block
+				  quote-block special-block src-block
+				  verse-block))
+      (user-error "Not at a block"))
+    (org-with-wide-buffer
+     (org-indent-region (org-element-property :begin element)
+			(org-element-property :end element))))
+  (message "Block at point indented"))
+
 
 ;;; Filling
 
-- 
1.9.2


  reply	other threads:[~2014-05-04 19:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-30 13:03 [RFC] Rewrite indentation functions Nicolas Goaziou
2014-04-30 17:08 ` Vikas Rawal
2014-04-30 18:59   ` Sebastien Vauban
2014-05-01 19:11 ` Nicolas Goaziou
2014-05-02  5:38 ` Eric Abrahamsen
2014-05-02  7:32   ` Nicolas Goaziou
2014-05-02 10:01     ` Eric Abrahamsen
2014-05-03  7:47     ` Eric Abrahamsen
2014-05-03  8:47       ` Eric Abrahamsen
2014-05-03 11:47         ` Nicolas Goaziou
2014-05-04  3:25           ` Eric Abrahamsen
2014-05-04  3:30           ` Eric Abrahamsen
2014-05-04 19:45             ` Nicolas Goaziou [this message]
2014-05-04  3:39           ` Eric Abrahamsen
2014-05-05  9:30             ` Nicolas Goaziou
2014-05-06  9:41 ` Bastien
2014-05-07  0:51   ` Eric Abrahamsen
2014-05-07 15:40   ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87eh09pbuc.fsf@gmail.com \
    --to=n.goaziou@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=eric@ericabrahamsen.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).