From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: [patch] org-delete-indentation Date: Sat, 16 May 2015 17:34:20 +0200 Message-ID: <87fv6wh6yr.fsf@gmx.us> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yte6i-0001aF-65 for emacs-orgmode@gnu.org; Sat, 16 May 2015 11:34:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yte6e-0002fM-VN for emacs-orgmode@gnu.org; Sat, 16 May 2015 11:34:32 -0400 Received: from plane.gmane.org ([80.91.229.3]:43866) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yte6e-0002fA-LD for emacs-orgmode@gnu.org; Sat, 16 May 2015 11:34:28 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Yte6b-0002kq-Rh for emacs-orgmode@gnu.org; Sat, 16 May 2015 17:34:25 +0200 Received: from 71.red-88-19-189.staticip.rima-tde.net ([88.19.189.71]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 16 May 2015 17:34:25 +0200 Received: from rasmus by 71.red-88-19-189.staticip.rima-tde.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 16 May 2015 17:34:25 +0200 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: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hi, Due to recent controversy about Org being lacking Microsoftesque detail I finally implemented org-delete-indentation, which is a function I have been missing forever. It only behaves differently from delete-indentation at headlines where it add stuff to the headline text. It is at least what I would expect. Examples: * foo :tag: bar| => (org-delete-indentation) * foo bar :tag: * foo | :tag: bar => (org-delete-indentation t) * foo bar :tag: —Rasmus -- With monopolies the cake is a lie! --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-org.el-New-function-org-delete-indentation.patch >From ef242f5d599d4888cdf57e1f6a65db8406626499 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Sat, 16 May 2015 17:19:03 +0200 Subject: [PATCH 2/2] org.el: New function org-delete-indentation * org.el (org-delete-indentation): New function. (org-mode-map): Bind org-delete-indentation to M-^. * test-org.el (test-org-delete-indentation): Test org-delete-indentation. * ORG-NEWS: Add entry on org-delete-indentation. --- etc/ORG-NEWS | 3 +++ lisp/org.el | 25 +++++++++++++++++++++++++ testing/lisp/test-org.el | 28 ++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index a3e1ae2..91e30f8 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -377,6 +377,9 @@ for details. Calling ~org-edit-footnote-reference~ (C-c ') on a footnote reference allows to edit its definition, as long as it is not anonymous, in a dedicated buffer. It works even if buffer is currently narrowed. +*** New function ~org-delete-indentation~ bound to ~M-^~ +Work as ~delete-indentation~ unless at heading, in which case text is +added to headline text. ** Miscellaneous *** Strip all meta data from ITEM special property ITEM special property does not contain TODO, priority or tags anymore. diff --git a/lisp/org.el b/lisp/org.el index 93183f9..f30c25c 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -19832,6 +19832,7 @@ boundaries." (org-defkey org-mode-map [remap comment-dwim] 'org-comment-dwim) (org-defkey org-mode-map [remap forward-paragraph] 'org-forward-paragraph) (org-defkey org-mode-map [remap backward-paragraph] 'org-backward-paragraph) +(org-defkey org-mode-map "\M-^" 'org-delete-indentation) (org-defkey org-mode-map "\C-m" 'org-return) (org-defkey org-mode-map "\C-j" 'org-return-indent) (org-defkey org-mode-map "\C-c?" 'org-table-field-info) @@ -21159,6 +21160,30 @@ This command does many different things, depending on context: (let ((org-note-abort t)) (funcall org-finish-function)))) +(defun org-delete-indentation (&optional ARG) + "Join this line to previous and fix up whitespace at join. + +If previous row is a headline add to headline text." + (interactive "*P") + (if (save-excursion (if ARG + (beginning-of-line) + (forward-line -1)) + (looking-at org-complex-heading-regexp)) + ;; At headline. + (let ((string (concat " " (prog2 (and ARG (forward-line 1)) + (org-trim (delete-and-extract-region (line-beginning-position) + (line-end-position))))))) + (when (eq (preceding-char) ?\n) (delete-region (point) (1- (point)))) + (goto-char (or (match-beginning 5) + (match-end 0))) + (skip-chars-backward " \t") + (when (and (match-beginning 5) + (< (+ (point) (length string)) + (match-beginning 5))) + (delete-region (point) (+ (point) (length string)))) + (save-excursion (insert string))) + (delete-indentation ARG))) + (defun org-open-line (n) "Insert a new row in tables, call `open-line' elsewhere. If `org-special-ctrl-o' is nil, just call `open-line' everywhere." diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index ecfece5..a241f26 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -833,6 +833,34 @@ ;;; Editing +(ert-deftest test-org-delete-indentation () + "Test M-^ (`org-delete-indentation') specification." + ;; Regular test. + (should (equal "foo bar" + (org-test-with-temp-text + "foo \n bar" + (org-delete-indentation) + (buffer-string)))) + ;; With optional argument. + (should (equal "foo bar" + (org-test-with-temp-text + "foo \n bar" + (org-delete-indentation t) + (buffer-string)))) + ;; At headline text should be appended to the headline text. + (should + (equal "* foo bar :tag:" + (org-test-with-temp-text + "* foo :tag:\n bar" + (org-delete-indentation) + (buffer-string)))) + (should + (equal "* foo bar :tag:" + (org-test-with-temp-text + "* foo :tag:\n bar" + (org-delete-indentation t) + (buffer-string))))) + (ert-deftest test-org/return () "Test RET (`org-return') specifications." ;; Regular test. -- 2.4.0 --=-=-=--