From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id qM7PLFzWO2RY9gAASxT56A (envelope-from ) for ; Sun, 16 Apr 2023 13:05:00 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id eEfOK1zWO2QxwAAAauVa8A (envelope-from ) for ; Sun, 16 Apr 2023 13:05:00 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 43A95D974 for ; Sun, 16 Apr 2023 13:05:00 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1po0BX-0002fn-IO; Sun, 16 Apr 2023 07:04:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1po0BS-0002fF-K8 for emacs-orgmode@gnu.org; Sun, 16 Apr 2023 07:04:39 -0400 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1po0BQ-0005dK-FX for emacs-orgmode@gnu.org; Sun, 16 Apr 2023 07:04:38 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 3BB47240114 for ; Sun, 16 Apr 2023 13:04:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1681643075; bh=fZXKLjqGpO582R/98mvYE969Tv/G80RRAIOyMJTbUeQ=; h=From:To:Cc:Subject:Date:From; b=lWfjlL0/B13laVJQ9tkGhgJWYbDHi1rL6tbNpP8IuJ2cxds7ApV+9dWmMBJm7xJrm bfHpNMqiIu1GxgL5zLqORJMk6y+bPIeLZiiq9nFw/qIs8WLeg0JsRs1aoszIUdiweN MhRzzzMDcfpK4h6+OVJfijWH8ySlX8mLEtDFgE6nB/oVd2wrzTLexAHeyYZt5tdYIJ aNqkZV3CsaYtsigNaSxHeTf7lhdVBm+/R6ad6oQKqqxS/CWdg/O/2yvvmHLHpCAdOW 0UaeIP+syT0pXqYAVbuN6AdJGmRovdeVAIjiXtfFO3oFb8LowS7oOWNBKeJFPBHJlJ x7oZs7GbrBCMA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4PznPt61j3z9rxD; Sun, 16 Apr 2023 13:04:34 +0200 (CEST) From: Ihor Radchenko To: Spencer Baugh Cc: emacs-orgmode@gnu.org Subject: Re: [BUG] org-delete-indentation on region doesn't work when END is before BEGIN [9.6.1 (release_9.6.1-40-g3d817c @ /home/sbaugh/.local/src/emacs29/lisp/org/)] In-Reply-To: References: Date: Sun, 16 Apr 2023 11:07:12 +0000 Message-ID: <87v8hwt7a7.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Seal: i=1; s=key1; d=yhetil.org; t=1681643100; a=rsa-sha256; cv=none; b=AgjjKJspm8uPaj+CtIWZkD+p4es9dKaEhGxozRQonbvw+m18LUtR4nCbyRrl20RwWRvHNB s29n3fx1INOZ7SRf5GroeMg/q85q/x0WKCkqNBP5SW8iswd7WwFDBN6vYGlbmeY4BD88KL Q3zoLko94ZDL1XdB/8dANaBlezwBiu+Bnl1StT+8TRyemvZ6WuDUhMt159rsdgErA4uQM/ apCInUqSRVpt/wG6Q+tUIC5VZFiaz/PSIqbWmagzlw8YTJbKFNqV/DeqW19GkMGRxhBOp5 U7nvTTEqIV+qO0uCfTyu9iYR7DJS9U2hcKkYKDtIn/7xk123GCvviSMzuXqdDA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="lWfjlL0/"; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1681643100; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=gPnz8Kgh97wztDXJMlNhDR0Ovowf8IGNGrKGuh5G8NM=; b=VDYNzGuCZIYtEmHK6UopumfIoCQVXgfZa5jwgYFN6SVTt3L1aztYkY6sJVP7QV0q71TlzJ NElU4vrzfK4+Wb8G3OSMBflpFc68XmV6bwmUjY2gtmxXu5Bf6afvyDPhZnSpUEwlmTHLJw 21PkvufGGSt0sCzgULoGKTgtU9yu9SuBa3hcCk8T/mZAPp8Km6HH38RG9GldnHq7COQyxA Ye9O+CE35eMLhMs6vcfjW5X9Q/1d4aC8afWPaV6+dElnaZsZ3iuw92ulVxpgDH0iJKWHF3 WpkU3p0vaSP69tfBGRKOMge/NMAsyhzplJOEkXrqKsNW+6la6QpSOOvsJuQIsg== X-Migadu-Queue-Id: 43A95D974 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="lWfjlL0/"; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=posteo.net X-Migadu-Scanner: scn0.migadu.com X-Migadu-Spam-Score: -8.00 X-Spam-Score: -8.00 X-TUID: XPM5T637FgT3 --=-=-= Content-Type: text/plain Spencer Baugh writes: > 1. emacs -Q > 2. Insert the following in an org-mode buffer > * head > a > b > 3. C-x h M-^ and note that it's now formatted as: > a > b > * head `org-delete-indentation' did not support regions properly. I tried to make things more consistent with `delete-indentation in the attached patch. May you please test the patch and let me know if there are any other inconsistencies you observe? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-delete-indentation-Support-region-selection.patch >From 6e9a09dd74e0fcb38563b1042163e95e3e43c4da Mon Sep 17 00:00:00 2001 Message-Id: <6e9a09dd74e0fcb38563b1042163e95e3e43c4da.1681642978.git.yantar92@posteo.net> From: Ihor Radchenko Date: Sun, 16 Apr 2023 13:00:40 +0200 Subject: [PATCH] org-delete-indentation: Support region selection * lisp/org.el (org-delete-indentation): Support active region when the first line in region is a heading. Clarify in the docstring that region is ignored with prefix argument. Reported-by: Spencer Baugh Link: https://orgmode.org/list/ier3552edfr.fsf@janestreet.com --- lisp/org.el | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 26d2a8610..9422fd587 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -17675,41 +17675,50 @@ (defun org-kill-note-or-show-branches () (org-fold-show-branches) (org-fold-hide-archived-subtrees beg end))))) -(defun org-delete-indentation (&optional arg) +(defun org-delete-indentation (&optional arg beg end) "Join current line to previous and fix whitespace at join. If previous line is a headline add to headline title. Otherwise the function calls `delete-indentation'. -I.e. with a non-nil optional argument, join the line with the -following one. If there is a region then join the lines in that -region." - (interactive "*P") +If there is a region (BEG END), then join the lines in that region. + +With a non-nil prefix ARG, join the line with the following one, +ignoring region." + (interactive + (cons current-prefix-arg + (when (and (not current-prefix-arg) (use-region-p)) + (list (region-beginning) (region-end))))) + (unless (and beg end) + ;; No region selected or BEG/END arguments not passed. + (setq beg (line-beginning-position (if arg 1 0)) + end (line-end-position (if arg 2 1)))) (if (save-excursion - (beginning-of-line (if arg 1 0)) - (let ((case-fold-search nil)) - (looking-at org-complex-heading-regexp))) + (goto-char beg) + (beginning-of-line) + (and (< (line-end-position) end) + (let ((case-fold-search nil)) + (looking-at org-complex-heading-regexp)))) ;; At headline. (let ((tags-column (when (match-beginning 5) (save-excursion (goto-char (match-beginning 5)) (current-column)))) - (string (concat " " (progn (when arg (forward-line 1)) - (org-trim (delete-and-extract-region - (line-beginning-position) - (line-end-position))))))) - (unless (bobp) (delete-region (point) (1- (point)))) + string) + (goto-char beg) + ;; Join all but headline. + (save-excursion (save-match-data (delete-indentation nil (line-beginning-position 2) end))) + (setq string (org-trim (delete-and-extract-region (line-end-position) (line-end-position 2)))) (goto-char (or (match-end 4) (match-beginning 5) (match-end 0))) (skip-chars-backward " \t") - (save-excursion (insert string)) + (save-excursion (insert " " string)) ;; Adjust alignment of tags. (cond ((not tags-column)) ;no tags (org-auto-align-tags (org-align-tags)) (t (org--align-tags-here tags-column)))) ;preserve tags column - (let ((current-prefix-arg arg)) - (call-interactively #'delete-indentation)))) + (funcall-interactively #'delete-indentation arg beg end))) (defun org-open-line (n) "Insert a new row in tables, call `open-line' elsewhere. -- 2.40.0 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--