unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Manuel Giraud <manuel@ledu-giraud.fr>
To: Eli Zaretskii <eliz@gnu.org>
Cc: larsi@gnus.org, 56335@debbugs.gnu.org
Subject: bug#56335: 29.0.50; [PATCH] Add more breakpoint chars support to longlines-mode
Date: Tue, 05 Jul 2022 15:07:14 +0200	[thread overview]
Message-ID: <87wncrzp19.fsf@elite.giraud> (raw)
In-Reply-To: <834jzx9ld5.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 04 Jul 2022 14:18:46 +0300")

[-- Attachment #1: Type: text/plain, Size: 421 bytes --]

Hi,

Here is a new patch for longlines-mode. It updates substring filtering
to the new interface and do not replace soft newlines with spaces
anymore. So now, copy/pasting from a longlines buffer should work as
intended.

I'm now trying to update the search/query-replace but I don't understand
how 'search-spaces-regex' works. It seems that with it I should be able
to jump above soft newlines during search, but how ?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-longlines-substring-update.patch --]
[-- Type: text/x-patch, Size: 3528 bytes --]

From 1a7eb36393aba16680765d34ae3e4329df7f397e Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
Date: Tue, 5 Jul 2022 14:38:43 +0200
Subject: [PATCH] [longlines] substring update

* lisp/longlines.el (longlines-mode, longlines-encode-string): Update
from `buffer-substring-filters' to `filter-buffer-substring-function'.
Remove soft newlines in substring.
---
 lisp/longlines.el | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/lisp/longlines.el b/lisp/longlines.el
index a6cf93a039..855fbc6e0e 100644
--- a/lisp/longlines.el
+++ b/lisp/longlines.el
@@ -118,7 +118,6 @@ longlines-mode
         (add-to-list 'buffer-file-format 'longlines)
         (add-hook 'change-major-mode-hook #'longlines-mode-off nil t)
 	(add-hook 'before-revert-hook #'longlines-before-revert-hook nil t)
-        (make-local-variable 'buffer-substring-filters)
         (make-local-variable 'longlines-auto-wrap)
 	(set (make-local-variable 'isearch-search-fun-function)
 	     #'longlines-search-function)
@@ -126,7 +125,8 @@ longlines-mode
 	     #'longlines-search-forward)
 	(set (make-local-variable 'replace-re-search-function)
 	     #'longlines-re-search-forward)
-        (add-to-list 'buffer-substring-filters 'longlines-encode-string)
+        (add-function :filter-return (local 'filter-buffer-substring-function)
+                      #'longlines-encode-string)
         (when longlines-wrap-follows-window-size
 	  (let ((dw (if (and (integerp longlines-wrap-follows-window-size)
 			     (>= longlines-wrap-follows-window-size 0)
@@ -143,7 +143,7 @@ longlines-mode
 	      (inhibit-modification-hooks t)
               (mod (buffer-modified-p))
 	      buffer-file-name buffer-file-truename)
-          ;; Turning off undo is OK since (spaces + newlines) is
+          ;; Turning off undo is OK since (separators + newlines) is
           ;; conserved, except for a corner case in
           ;; longlines-wrap-lines that we'll never encounter from here
 	  (save-restriction
@@ -202,7 +202,8 @@ longlines-mode
     (kill-local-variable 'replace-search-function)
     (kill-local-variable 'replace-re-search-function)
     (kill-local-variable 'require-final-newline)
-    (kill-local-variable 'buffer-substring-filters)
+    (remove-function (local 'filter-buffer-substring-function)
+                     #'longlines-encode-string)
     (kill-local-variable 'use-hard-newlines)))
 
 (defun longlines-mode-off ()
@@ -385,15 +386,22 @@ longlines-encode-region
       end)))
 
 (defun longlines-encode-string (string)
-  "Return a copy of STRING with each soft newline replaced by a space.
+  "Return a copy of STRING with each soft newline removed.
 Hard newlines are left intact."
-  (let* ((str (copy-sequence string))
-         (pos (string-search "\n" str)))
-    (while pos
-      (if (null (get-text-property pos 'hard str))
-          (aset str pos ? ))
-      (setq pos (string-search "\n" str (1+ pos))))
-    str))
+  (let ((str (copy-sequence string))
+        (start 0)
+        (result nil))
+    (while (setq pos (string-search "\n" str start))
+      (unless (= start pos)
+        (push (substring str start pos) result))
+      (when (get-text-property pos 'hard str)
+        (push (substring str pos (1+ pos)) result))
+      (setq start (1+ pos)))
+    (if (null result)
+        str
+      (unless (= start (length str))
+        (push (substring str start) result))
+      (apply #'concat (nreverse result)))))
 
 ;;; Auto wrap
 
-- 
2.36.1


[-- Attachment #3: Type: text/plain, Size: 18 bytes --]

-- 
Manuel Giraud

  reply	other threads:[~2022-07-05 13:07 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-01 10:35 bug#56335: 29.0.50; [PATCH] Add more breakpoint chars support to longlines-mode Manuel Giraud
2022-07-01 13:33 ` Manuel Giraud
2022-07-02 12:14 ` Lars Ingebrigtsen
2022-07-02 12:23   ` Visuwesh
2022-07-02 12:46     ` Phil Sainty
2022-07-02 12:39   ` Eli Zaretskii
2022-07-02 12:44     ` Lars Ingebrigtsen
2022-07-02 13:03       ` Eli Zaretskii
2022-07-02 15:39         ` Lars Ingebrigtsen
2022-07-02 21:19           ` Manuel Giraud
2022-07-03  5:14             ` Eli Zaretskii
2022-07-04  8:06               ` Manuel Giraud
2022-07-04 11:18                 ` Eli Zaretskii
2022-07-05 13:07                   ` Manuel Giraud [this message]
2022-07-05 16:32                     ` Lars Ingebrigtsen
2022-07-06  7:43                       ` Manuel Giraud
2022-07-06 11:18                         ` Lars Ingebrigtsen
2022-07-06 10:18                       ` Manuel Giraud
2022-07-06 11:20                         ` Lars Ingebrigtsen
2022-07-06 18:49                         ` Juri Linkov
2022-07-06 20:47                           ` Manuel Giraud
2022-07-08  3:32                             ` Richard Stallman
2022-07-08  7:14                               ` Manuel Giraud
2022-07-08  7:22                                 ` Eli Zaretskii
2022-07-10  8:58                                   ` Manuel Giraud
2022-07-10 13:02                                     ` Lars Ingebrigtsen

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wncrzp19.fsf@elite.giraud \
    --to=manuel@ledu-giraud.fr \
    --cc=56335@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=larsi@gnus.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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).