From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Arthur Miller Newsgroups: gmane.emacs.devel Subject: Why does this re-search forward fail? Date: Tue, 20 Apr 2021 15:56:07 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10811"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (windows-nt) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Apr 20 15:56:52 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lYqs0-0002dM-4r for ged-emacs-devel@m.gmane-mx.org; Tue, 20 Apr 2021 15:56:52 +0200 Original-Received: from localhost ([::1]:38500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYqrz-0000Zk-6K for ged-emacs-devel@m.gmane-mx.org; Tue, 20 Apr 2021 09:56:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYqrP-00005C-8z for emacs-devel@gnu.org; Tue, 20 Apr 2021 09:56:15 -0400 Original-Received: from mail-oln040092075031.outbound.protection.outlook.com ([40.92.75.31]:57409 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYqrM-000242-Ph for emacs-devel@gnu.org; Tue, 20 Apr 2021 09:56:14 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PrV3KZCF/8VcKRC/3i/H1D6cRSjZCrWSjjhZoFySktGNrHJw1pZDqiDACJQa9gy5umNk1oGoqqiR1yaXg6ofZdYtyfAjXFCwDurVCL44GiLRdagSS/v4/K3DYolKlnuqZgzYmxWN7S7/SEKOcPNpFYGcpgoLwgOvTrzO4qxSIc8MpD2mMlCjotxJgf1FhvBxXJnfWdHHOzJ1Er4ToPnTZjkOegzAV3OIXc8/uEciyp8qD/aXSjEedwYg2ArcaAuw30/+sEP7wTfolq4SfveNmT4KGMy0e1JYEWcEgv4sycf28AfRN8jfx+sYV+m0R4zBtAWrF2gptj6Fg14jpLKHZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wklnyZWCuffe/gHcP5/bP7NsGaxIUxu0c1JkgjTbfPY=; b=PT08nQZACx6SEWyda2fQ49jt083/wl8Ad868x6fW9Tg0oJL4UQLIQ5SUT4fSqIbaln/F567KUFrZg4YY2TXZ1TQR5SxvZjdgQmFOIfm1wOfA7ibLrmrnnsr/IDcDEpHYL8wpgZzIZOROXT3vxvv/vwGwnzCd91V//BtdMKXG/h0ygSdwJ3UaP3WztzLeY5YTjrztFFUbOSYg7J7GkmXQsNwWOLNNy3LwV781Gzlzh7hZ5WhYexfG/VEi7hdkmpZbx0N7BEGnIAdFPchOwCfD817vK1lbI//ReU0NdIATnZVz2dwswco1wzVlH2CFxNAYEDsQNEfGNLHEYJxI2ZGlHw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wklnyZWCuffe/gHcP5/bP7NsGaxIUxu0c1JkgjTbfPY=; b=Yv23tJxJVi2ONT60+kKmqFMJ+dFrgMHzBXVrv1ydOBxRlcbUtB2TEQYJk2SOhD4vBhlWVAdZwp/7IK+HqOQowmmXnyJe5Ilay2xN6PyYrULhK8y3YSgXgChQAFqrkL5Gb+CJ7IBa4u/YVY36N3MIgN0KHSZqVKT35FL0we6Ez6gKAjdmoPk2yJTOn9Wejickl9NnfzCHF8ky9Fpbft95/YMRTjdLotCsIdFXRYb6DtoPPrEVceqp3XxG4e4Xs8QDZgJ9FnHKM0ZcsQxfWtMkpfl64PgWvc+/KZUNknH2LnjZBLVrf3HkbdUy6w97DrgvjbyRZxrun/NTvN5bqZAxmA== Original-Received: from DB3EUR04FT047.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::49) by DB3EUR04HT164.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::369) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Tue, 20 Apr 2021 13:56:10 +0000 Original-Received: from AM9PR09MB4977.eurprd09.prod.outlook.com (2a01:111:e400:7e0c::51) by DB3EUR04FT047.mail.protection.outlook.com (2a01:111:e400:7e0c::293) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 13:56:10 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:0DF23DEB08D2CD2E81AF7CF8FCE2736923C865A436E28E5031A935827BA87030; UpperCasedChecksum:97233B18FBBCE847DBCBBC04EDBAC39CA60BDDDF5A300539323ECF092EDF2AD8; SizeAsReceived:7210; Count:43 Original-Received: from AM9PR09MB4977.eurprd09.prod.outlook.com ([fe80::2103:e705:bc0c:5a8b]) by AM9PR09MB4977.eurprd09.prod.outlook.com ([fe80::2103:e705:bc0c:5a8b%6]) with mapi id 15.20.4042.024; Tue, 20 Apr 2021 13:56:10 +0000 X-TMN: [UsMlMarAPMf/hqnbeLsu0BE4vIaXw0+c] X-ClientProxiedBy: AM5P194CA0016.EURP194.PROD.OUTLOOK.COM (2603:10a6:203:8f::26) To AM9PR09MB4977.eurprd09.prod.outlook.com (2603:10a6:20b:304::20) X-Microsoft-Original-Message-ID: <827dkxxdoo.fsf@live.com> X-MS-Exchange-MessageSentRepresentingType: 1 Original-Received: from HP-Laptop.homepc (81.232.177.30) by AM5P194CA0016.EURP194.PROD.OUTLOOK.COM (2603:10a6:203:8f::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Tue, 20 Apr 2021 13:56:08 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 43 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 40dfc7ab-3fab-4aa6-e408-08d904040ca6 X-MS-TrafficTypeDiagnostic: DB3EUR04HT164: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: doBs87WloADYMj0rUnlDmBBHZYwkDaObGrgSSHK7gwKEbq3UpSfQTBGdKZ11KtuiOPLIMCJp14gtBghvzT/9x3GnivolDPamHY1d+u0zA41qwnmHIxcwHzRZt5b7uYtN+nMrecI14u875jCIzq/I2yYnQUJsryUfV4PuiOwsmnmK7MBTSkkZ9928M3xOoSVAKScTHxLwZmSOuJ36rCLBqAdbvC7epIwsyXJnGglkQtHEj2KldD7OMy7kf+AExsLqnchVJmlWWU/4vnux0LA7PKrWyI08fIN9KHg9PI8lGsPKHDudf6hUtsJ4hdgAqLdqb0ojSTfbptoY3R37L4UPdkk4CX6SKLhaRNh3fDSnXfPPiRu872l6Xt8/mlCHzAyC/zGNPZ9h/4lsEEWTliiUbA== X-MS-Exchange-AntiSpam-MessageData: HySNsWPqhjmmqjVn/RtpohMOGD+dZQatmBDa2zjoLtpRvr3ZroScEjX2kAQc4LIsizhiI1/T3EORPdvS35eTAOYWzXRciAIPNTsE7miJh2fZi+wCQFUTdIJHLbdrzsIcyrC3lCDoeqDm1PaSdvztsg== X-OriginatorOrg: live.com X-MS-Exchange-CrossTenant-Network-Message-Id: 40dfc7ab-3fab-4aa6-e408-08d904040ca6 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2021 13:56:10.3961 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DB3EUR04FT047.eop-eur04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3EUR04HT164 Received-SPF: pass client-ip=40.92.75.31; envelope-from=arthur.miller@live.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:268205 Archived-At: --=-=-= Content-Type: text/plain Hello, in rare and spare moments when I am not feeding the cutiest best of all cute beasts or changing her diapers, I was playing with a little idea to hide org-babel markers in my init file. I wrote a small minor mode for this, which I have attached in this mail. There is a small problem with the loop, where the main action is happening: #+begin_src emacs-lisp (while (re-search-forward hbm--src-marker-re (eobp) t) (hbm--update-line visibility)) #+end_src The RE I search for is: (defvar hbm--src-marker-re "^[ \t]*#\\+\\|begin_src\\|end_src") What is happeneing is that for some strange reason, the search jumps over some lines or stop working. If I disable/enable the mode, same lines that failed, work. I also wrote a small aritificial test, that will generate 200 src blocks in a test file, and what I see there is that search fails after ~ 55 blocks, every time. Since all 200 blocks are machine generated I see no reason why search would fail. I also tested to iterate through the file with more explicit loop that went line by line through entire line, but with same result. #+begin-src emacs-lisp (defun hbm--update-markers (visibility) (save-excursion (goto-char (point-min)) (with-silent-modifications (while (not (eobp)) (beginning-of-line) (when (re-search-forward hbm--src-marker-re (eobp) t) (hbm--update-line visibility)) (forward-line))))) #+end_src Any idea? The Emacs at hand is 27.1 (build 1, x86_64-w64-mingw32) of 2020-08-21. The test was done with -Q option. --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=ob-hide-markers.el Content-Transfer-Encoding: quoted-printable ;;; ob-hide-markers.el --- Hide or-babel source code markers. -*- lexical-= binding: t; -*-=0D =0D ;; Copyright (C) 2021 Arthur Miller=0D =0D ;; Author: Arthur Miller =0D ;; Keywords: convenience, outlines, tools=0D =0D ;; This program is free software; you can redistribute it and/or modify=0D ;; it under the terms of the GNU General Public License as published by=0D ;; the Free Software Foundation, either version 3 of the License, or=0D ;; (at your option) any later version.=0D =0D ;; This program is distributed in the hope that it will be useful,=0D ;; but WITHOUT ANY WARRANTY; without even the implied warranty of=0D ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0D ;; GNU General Public License for more details.=0D =0D ;; You should have received a copy of the GNU General Public License=0D ;; along with this program. If not, see .= =0D =0D ;;; Commentary:=0D =0D ;; A minor mode to help reduce clutter in org-babel code blocks by=0D ;; hiding/unhiding markers for source code blocks in org-mode.=0D ;;=0D ;; To hide all markers turn on org-hbm-mode by=0D ;;=0D ;; `M-x org-hbm-mode.'=0D ;;=0D ;; To turn it off execute same command.=0D ;;=0D ;; The mode provides two additional interactive commands.=0D ;;=0D ;; Use `hbm-refresh' if you add new code blocks, copy-paste etc.=0D ;;=0D ;; Alternatively it is possible to turn on/off markers for an individual so= urce=0D ;; code by executing `M-x hbm-toggle-current-block'. It does not require=0D ;; org-hbm-mode to be on, but you will have to call it again to make marker= s=0D ;; visible again.=0D ;;=0D ;; It is possible to somewhat control the appereance of org-file by customi= zing=0D ;; the `orh-hbm-hide-marker-line' variable. When this variable is nil, mark= ers=0D ;; will be invisible but the newline character will be left visible resulti= ng in=0D ;; somewhat "fluffier" appereance. Whan the value is set to `t' even newlin= e=0D ;; character will be hidden resulting in more dense and compact code. That = might=0D ;; not be for everyone, so sett it to your own preference. It is `nil' by= =0D ;; default.=0D =0D ;;; Code:=0D (defcustom org-babel-hide-markers-line nil=0D "If value of this variable is `t', org-hbm mode vill hide also line on wh= ich=0D source code block markers are, otherwise only markers are hidden leaving = an=0D empty line."=0D :group 'org-babel=0D :tag "Org Babel Hide Source Block Markers Line")=0D =0D (defvar hbm--src-end-re "^[ \t]*#\\+end_src")=0D (defvar hbm--src-start-re "^[ \t]*#\\+begin_src")=0D (defvar hbm--src-marker-re "^[ \t]*#\\+\\|begin_src\\|end_src")=0D =0D (defun hbm--update-line (visibility)=0D (put-text-property=0D (if org-babel-hide-markers-line=0D (1- (line-beginning-position))=0D (line-beginning-position))=0D (line-end-position) 'invisible visibility))=0D =0D (defun hbm--update-markers (visibility)=0D (save-excursion=0D (goto-char (point-min))=0D (with-silent-modifications=0D (while (re-search-forward hbm--src-marker-re (eobp) t)=0D (hbm--update-line visibility)))))=0D =0D (defun hbm--marker-hidden-p ()=0D (get-text-property (line-beginning-position) 'invisible))=0D =0D (defun hbm--toggle-line-visibility (pos)=0D "Toggle visiility of a line at position."=0D (save-excursion=0D (goto-char pos)=0D (if (hbm--marker-hidden-p)=0D (hbm--update-line nil)=0D (hbm--update-line t))))=0D =0D ;;;###autoload=0D (defun org-babel-toggle-current-block ()=0D (interactive)=0D (save-excursion=0D (let (found (start (point)) end)=0D (goto-char (line-beginning-position))=0D (with-silent-modifications=0D (setq found (re-search-forward hbm--src-start-re=0D (line-end-position) t))=0D (unless found=0D (goto-char start)=0D (setq start (re-search-backward hbm--src-start-re)))=0D (setq end (re-search-forward hbm--src-end-re))=0D (when (and start end)=0D (hbm--toggle-line-visibility start)=0D (hbm--toggle-line-visibility end))))))=0D =0D ;;;###autoload=0D (defun org-babel-refresh-markers ()=0D (interactive)=0D (unless org-babel-hide-markers-mode=0D (error "Not in org-hide-babel-markers mode."))=0D (hbm--update-markers t))=0D =0D ;;;###autoload=0D (define-minor-mode org-babel-hide-markers-mode=0D "Hide/show babel source code blocks on demand."=0D :global nil=0D :init-value t=0D :lighter " OB Hmm"=0D (unless (derived-mode-p 'org-mode)=0D (error "Not in org-mode."))=0D (if org-babel-hide-markers-mode=0D (hbm--update-markers t)=0D (hbm--update-markers nil)))=0D =0D (defun gen-test ()=0D (with-temp-file "test.org"=0D (insert "* Test")=0D (newline)=0D (dotimes (i 200)=0D (insert (format "** Block %s" (1+ i)))=0D (newline)=0D (insert "#+begin_src emacs-lisp")=0D (newline) (newline)=0D (insert "#+end_src")=0D (newline))))=0D =0D (provide 'ob-hide-markers)=0D =0D ;;; ob-hide-markers.el ends here=0D --=-=-=--