From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [RFC] Rewrite indentation functions Date: Sun, 04 May 2014 21:45:15 +0200 Message-ID: <87eh09pbuc.fsf@gmail.com> References: <87oazjnf55.fsf@gmail.com> <87d2fwhh95.fsf@ericabrahamsen.net> <87fvksoctz.fsf@gmail.com> <87oazffgne.fsf@ericabrahamsen.net> <8738grw8nn.fsf@ericabrahamsen.net> <87tx97ozhr.fsf@gmail.com> <87r44ab4q2.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wh2LD-0001I6-75 for emacs-orgmode@gnu.org; Sun, 04 May 2014 15:44:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wh2L7-0003j6-CK for emacs-orgmode@gnu.org; Sun, 04 May 2014 15:44:51 -0400 Received: from mail-wg0-x229.google.com ([2a00:1450:400c:c00::229]:38921) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wh2L7-0003iz-1w for emacs-orgmode@gnu.org; Sun, 04 May 2014 15:44:45 -0400 Received: by mail-wg0-f41.google.com with SMTP id z12so1361931wgg.0 for ; Sun, 04 May 2014 12:44:44 -0700 (PDT) In-Reply-To: <87r44ab4q2.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Sun, 04 May 2014 11:30:29 +0800") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Abrahamsen Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Eric Abrahamsen writes: > Perhaps we need a new version of patch 3? Here it is. Regards, -- Nicolas Goaziou --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0003-Rewrite-org-indent-drawer-and-org-indent-block.patch >From 66d0ab7d1025969e5fd383b93ffe1fb1b05a83a8 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou 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 --=-=-=--