From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help Subject: Re: Run `fill-paragraph' on all the paragraphs in the currently opened LaTeX document. Date: Mon, 18 Oct 2021 18:28:10 +0200 Message-ID: <877dea70x1.fsf@zoho.eu> References: Reply-To: Emanuel Berg Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="677"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:QX1mxMBUjigU1O2YLedmy2/PonM= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 18 18:31:42 2021 Return-path: Envelope-to: geh-help-gnu-emacs@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 1mcVY5-000AX7-Ts for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 18 Oct 2021 18:31:41 +0200 Original-Received: from localhost ([::1]:46520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcVY4-0006KW-Ry for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 18 Oct 2021 12:31:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcVWZ-0006Hr-Ex for help-gnu-emacs@gnu.org; Mon, 18 Oct 2021 12:30:07 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]:44420) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcVWX-0008W3-4S for help-gnu-emacs@gnu.org; Mon, 18 Oct 2021 12:30:07 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1mcVWU-0008Rq-4A for help-gnu-emacs@gnu.org; Mon, 18 Oct 2021 18:30:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Mail-Copies-To: never Received-SPF: pass client-ip=116.202.254.214; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:133865 Archived-At: Hongyi Zhao wrote: > So the idea suggested by Emanuel Berg and you now can be > combined into the following: > > Iterate the whole buffer line-by-line with a semantic line > as the unit block, and check each line if it starts with '\' > or not, e.g. with (looking-at "\\\\"). When you find one > "beg", start looking for where it ends, and when you find > that push (beg end) onto a list. > > Then loop through the list and do (fill-region beg end) for > each list pair item ... Heh, interesting :) But I think the advantage of semantic lines in terms of filling is they will be so short that won't be necessary, if one still does it maybe it will just be confusing (neither fish nor fowl). BTW one can optimize the algorithm proposed above by searching for regexps instead of the line-by-line approach ... also it is a good case for a DWIM interface, so, when used interactively, the whole buffer will be filled that way only if there is no region ... ;;; -*- lexical-binding: t -*- ;;; ;;; this file: ;;; https://dataswamp.org/~incal/emacs-init/dwim.el ;; DWIM interface (defun test-dwim (&optional beg end) (interactive (when (use-region-p) (list (region-beginning) (region-end)) )) (let ((bg (or beg (point-min))) ; or just (point) here (ed (or end (point-max))) ) (list bg ed) ; code here )) ;; test the interface (when nil (save-excursion (set-mark 10) (goto-char 500) (call-interactively #'test-dwim) ) ; (10 500) (call-interactively #'test-dwim) ; ( 1 1163) (test-dwim 30 90) ; (30 90) (test-dwim) ; ( 1 1163) ) ;; example function (defun count-chars (&optional beg end) (interactive (when (use-region-p) (list (region-beginning) (region-end)) )) (let*((bg (or beg (point-min))) (ed (or end (point-max))) (diff (- ed bg)) ) (prog1 diff (message "%d" diff) ))) ;; test the example function ;; (call-interactively #'count-chars) ; 1162 ;; (count-chars) ; 1162 ;; (count-chars 10 40) ; 30 ;; (+ 1111 (count-chars)) ; 2273 -- underground experts united https://dataswamp.org/~incal