From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 4JAqGXqqOmPyZgEAbAwnHQ (envelope-from ) for ; Mon, 03 Oct 2022 11:25:14 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id wN4QGXqqOmOQEwAAauVa8A (envelope-from ) for ; Mon, 03 Oct 2022 11:25:14 +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 D2ADA36ADD for ; Mon, 3 Oct 2022 11:25:13 +0200 (CEST) Received: from localhost ([::1]:34102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofHhI-0004Rm-Ue for larch@yhetil.org; Mon, 03 Oct 2022 05:25:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofHf1-0003v8-OW for emacs-orgmode@gnu.org; Mon, 03 Oct 2022 05:22:51 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:34623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofHez-0008Sx-QI for emacs-orgmode@gnu.org; Mon, 03 Oct 2022 05:22:51 -0400 Received: by mail-pl1-x629.google.com with SMTP id n7so9184217plp.1 for ; Mon, 03 Oct 2022 02:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date; bh=2Zuf6l6M0LPDvzOX+MPokoWvfYHOoEjHKBSG0MzvUeQ=; b=NwP4YCWYEmO2OWNOy28RzJ0iiVKywAAfwvkSx2RIIowCqkyZR9V1vJQAYlrmUmpbPy 1gr5flOWzpyuSGp2VBOuNCqEZcs2S6BfNxujCGzYRv3mIZlmyHi6KGRggH2QPWdIKhqg 1BgHwqUjG0rrU9YgVoBsnxEfnKZTqZVWFKQc/jS//Lfma/4XpYOBGPwxMF0QJ8XZ6noS ARU50msA/NZ89clUG26CCcItzn5tJHtmrXpZpTnbK10lE7pg29iS/E/ypxDCzyDK3ERO B/GwuTirp6UXhzDiFl+GWzSWzHyR8lYhIdB7GnqodXyQ1EScWAm7w4mChbrD8K5e0tnD Eywg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date; bh=2Zuf6l6M0LPDvzOX+MPokoWvfYHOoEjHKBSG0MzvUeQ=; b=EAIjnbwThYlRJfln5fy1eqRkQWdth+gBJlQeSr0eGluzeW586Q3hiKMNT58d2SA8P4 e8Cj1bGVO4A68RPKgvxJH17GkxDRGotjJfEqZyAjFmToMkeqiZAX5zOBuPPsWaq/tmkr Lh2qbq0QR97p6GRMyYz+EX4mlN4yTD2nXIozcAppZX+YMWQ2Efwc4rO3CoNDKhvkQyt9 oOsArm8vY86gwJccDbUiKHBq1S872RTUOwGBW8QOlymgAWlyIkeBtvYO9C6HiZtf2HAb cz8Ro/xzIlh81bKIl58ciFXmaznMP82+Fc9qD2JrSJpRSrdWdXnxo7u97rzBZWpx6tqi bFVQ== X-Gm-Message-State: ACrzQf0V2NKOwSXR7O7LmH0vZkOQclCWll1lyC97PAGP+fYt6HeKTzff C+PJGq8eUBurD0Bp9jFhRTk= X-Google-Smtp-Source: AMsMyM7CBDTBtJJPD9gw4kiiD/r/P09kieIjLl6HWzSiqPzFzqF/NNDtsF7V56wT1DO776hRWvY/uQ== X-Received: by 2002:a17:90b:1e49:b0:203:38c:365a with SMTP id pi9-20020a17090b1e4900b00203038c365amr11233915pjb.133.1664788968062; Mon, 03 Oct 2022 02:22:48 -0700 (PDT) Received: from localhost ([1.83.154.214]) by smtp.gmail.com with ESMTPSA id i16-20020a170902c95000b001754064ac31sm6685984pla.280.2022.10.03.02.22.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 02:22:47 -0700 (PDT) From: Ihor Radchenko To: sebastien.miquel@posteo.eu Cc: Fabio Natali , emacs-orgmode Subject: Re: `org-fill-paragraph' (`M-q') in Org Mode source blocks In-Reply-To: <201b44de-1f97-1b23-1767-970ee00f259c@posteo.eu> References: <87y1txwgat.fsf@localhost> <201b44de-1f97-1b23-1767-970ee00f259c@posteo.eu> Date: Mon, 03 Oct 2022 17:23:40 +0800 Message-ID: <87mtadw99f.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=yantar92@gmail.com; helo=mail-pl1-x629.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1664789114; 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=2Zuf6l6M0LPDvzOX+MPokoWvfYHOoEjHKBSG0MzvUeQ=; b=XOOSkmrIM3GgVSLKwUAeagA7P/iMcbqBB9G8/dyvPxfMqQny7rPL+crWRhNMefxhzwoXi3 ST53N3XuepUMUfwjs6lhsmSRQui6Udx9OvhnySymu9BvCLOJA/1Z71OguOYOL2B0Ev53G7 7M19jpJE+xME880anNJXLTQ34uP92femc1MZjlHQrrQLZGdGxZP5rUcnniPxx9WBNVf17A pJPNp5fPevF0iqiiuOg6wjGh4mmrWSqynGwhvg3CYNtq8Oak0+v7iaBQOQM5PckygJbwJ+ gNCncLEp7R43e6BNNLGnIwQbv0rc3B3r7BpXw39cxSWu6xi4rvSa+TYrgzeY0w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664789114; a=rsa-sha256; cv=none; b=tUX9b6tsUIt5pzCSGBa+ID/8Rds5Xq8F9wB2Vg++jXYmKVbT/V1Ii1nINlp119SRCHALTA 2K2abaAo/x3DJ0xp7J/9+b5bPle0/a6oXXKJe9VpLtKnebmwR8HEaHjZ+H16YiB60A9Z2M VHJHdlJ4qToCLerdUp9KM2zrdAesTCSE0F4csb0Amlv4Fdo0y3XogFkVEvO3GhXuhYxySb SKj9YfwXt8u/VTa5X/WotGAUDzsmvI/1MH7HYcQMMVAhVywxzhBlaGdILQklw8FyeDU41N r6nPCVpjp++uctP8b4FkzYXTRSGlVnPfDM37n+/qWQdneg+CCW4/flwIUEm0yA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=NwP4YCWY; dmarc=pass (policy=none) header.from=gmail.com; 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" X-Migadu-Spam-Score: -3.35 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=NwP4YCWY; dmarc=pass (policy=none) header.from=gmail.com; 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" X-Migadu-Queue-Id: D2ADA36ADD X-Spam-Score: -3.35 X-Migadu-Scanner: scn1.migadu.com X-TUID: HUxnBaBub9xa --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable S=C3=A9bastien Miquel writes: >> Try >> 1. emacs -Q >> 2. insert >> ;; A comment >> (+ 2 2) >> 3. M-h M-q >>=20 >> Is it emacs-lisp-mode bug? Or is it illegal to fill-region in source >> code buffers? > > I think the original report is about M-q, not M-h M-q. M-q behaves as=20 > expected in emacs-lisp-mode. > > Currently, org-fill-paragraph will not work properly when called inside=20 > src blocks. This can be easily fixed, but probably requires yet another=20 > org-fill-paragraph-act-natively variable. See the attached. I am not sure if we really need the variable. AFAIU, acting natively was the default in the past for M-q with no region selection. Then, I "fixed" some bug report in 05ee1e6ee06db and introduced the bug herein. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-fill-element-Respect-region-selection-when-filli.patch >From 8777839a4fe5da6c9a780eac946e1a8a892d4f22 Mon Sep 17 00:00:00 2001 Message-Id: <8777839a4fe5da6c9a780eac946e1a8a892d4f22.1664788728.git.yantar92@gmail.com> From: Ihor Radchenko Date: Mon, 3 Oct 2022 17:03:15 +0800 Subject: [PATCH] org-fill-element: Respect region selection when filling src-block * lisp/org.el (org-fill-element): When region is not active, run `fill-paragraph' at point inside src block. When region is active and within src block boundaries, run `fill-paragraph' preserving the region. When region is active and crosses src block boundaries, fill the whole src block. Reported-by: Fabio Natali Fixes: https://orgmode.org/list/201b44de-1f97-1b23-1767-970ee00f259c@posteo.eu --- lisp/org.el | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 036384a04..23cf4198e 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -19135,11 +19135,18 @@ (defun org-fill-element (&optional justify) ;; the buffer. In that case, ignore filling. (cl-case (org-element-type element) ;; Use major mode filling function is source blocks. - (src-block (org-babel-do-in-edit-buffer - (push-mark (point-min)) - (goto-char (point-max)) - (setq mark-active t) - (funcall-interactively #'fill-paragraph justify 'region))) + (src-block + (let ((regionp (region-active-p))) + (org-babel-do-in-edit-buffer + ;; `org-babel-do-in-edit-buffer' will preserve region if it + ;; is within src block contents. Otherwise, the region + ;; crosses src block boundaries. We re-fill the whole src + ;; block in such scenario. + (when (and regionp (not (region-active-p))) + (push-mark (point-min)) + (goto-char (point-max)) + (setq mark-active t)) + (funcall-interactively #'fill-paragraph justify 'region)))) ;; Align Org tables, leave table.el tables as-is. (table-row (org-table-align) t) (table -- 2.35.1 --=-=-= 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 --=-=-=--