From: Rasmus <rasmus@gmx.us>
To: emacs-orgmode@gnu.org
Subject: Re: [patch] org-delete-indentation
Date: Sat, 16 May 2015 21:05:38 +0200 [thread overview]
Message-ID: <87h9rcfim5.fsf@gmx.us> (raw)
In-Reply-To: 87fv6wh6yr.fsf@gmx.us
[-- Attachment #1: Type: text/plain, Size: 480 bytes --]
Rasmus <rasmus@gmx.us> writes:
> 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.
Updated patch attached. It now uses (org-fix-tags-on-the-fly). A
consequence of this is that (i) it works with entities; (ii) it is very
strict about org-tag-column. But I guess so is C-c C-c on headlines, so
maybe it is not an issue.
Rasmus
--
Summon the Mothership!
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-org.el-New-function-org-delete-indentation.patch --]
[-- Type: text/x-diff, Size: 4070 bytes --]
From 31ac966a7913de5a6cd3fb81e2ad4abfa3413d61 Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@gmx.us>
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 | 22 ++++++++++++++++++++++
testing/lisp/test-org.el | 28 ++++++++++++++++++++++++++++
3 files changed, 53 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 8527c2d..59a2653 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)
@@ -20976,6 +20977,27 @@ 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")
+ (save-excursion (insert string))
+ (org-fix-tags-on-the-fly))
+ (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 @@
\f
;;; 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<point>"
+ (org-delete-indentation)
+ (buffer-string))))
+ ;; With optional argument.
+ (should (equal "foo bar"
+ (org-test-with-temp-text
+ "foo<point> \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<point>"
+ (org-delete-indentation)
+ (buffer-string))))
+ (should
+ (equal "* foo bar :tag:"
+ (org-test-with-temp-text
+ "* foo <point>:tag:\n bar"
+ (org-delete-indentation t)
+ (buffer-string)))))
+
(ert-deftest test-org/return ()
"Test RET (`org-return') specifications."
;; Regular test.
--
2.4.0
next prev parent reply other threads:[~2015-05-16 19:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-16 15:34 [patch] org-delete-indentation Rasmus
2015-05-16 19:05 ` Rasmus [this message]
2015-05-17 8:33 ` Nicolas Goaziou
2015-05-17 8:35 ` Nicolas Goaziou
2015-05-17 13:21 ` Rasmus
2015-05-20 22:48 ` Rasmus
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h9rcfim5.fsf@gmx.us \
--to=rasmus@gmx.us \
--cc=emacs-orgmode@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.