unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dima Kogan <dima@secretsauce.net>
To: Lars Magne Ingebrigtsen <larsi@gnus.org>
Cc: 17558@debbugs.gnu.org
Subject: bug#17558: 24.4.50; global-subword-mode breaks ERC
Date: Sat, 09 Jan 2016 10:14:51 -0800	[thread overview]
Message-ID: <87twmmhb6s.fsf@secretsauce.net> (raw)
In-Reply-To: <m3k2njp1j0.fsf@gnus.org>

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

Lars Magne Ingebrigtsen <larsi@gnus.org> writes:

>> The attached patch thus has no changes to this hunk. Let me know if you
>> think of a nicer way to do this.
>
> This still seems very difficult to understand.  The old version has a
> clear loop condition
>
>> -      (while (forward-word 1)
>
> while in the new version everything is inside a progn, making it kinda
> difficult to follow.

Aaah, I see the complaint now. New patch attached.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ERC-no-longer-gets-confused-by-subword-mode.patch --]
[-- Type: text/x-diff, Size: 3805 bytes --]

From ba2f53e864cc36a3a9296104975407274b59b601 Mon Sep 17 00:00:00 2001
From: Dima Kogan <dima@secretsauce.net>
Date: Tue, 30 Dec 2014 23:29:21 -0800
Subject: [PATCH] ERC no longer gets confused by subword-mode

In commit 6ddc44225e743e2b2a0d5c192f50aefd7a4a915b subword-mode was
integrated into the syntax table instead of simply remapping the
interactive motion bindings as was done previously.  This had the
unintended effect of changing the behavior of lisp programs that touch
words.  In the case of ERC, it completely broke it: emacs now throws an
error when ERC is launched, making it unusable when subword-mode is
active.

This commit replaces the word-oriented calls with ones that navigate
the buffer using syntax classes

Closes: #17558
---
 lisp/erc/erc-backend.el | 28 +++++++++++++++++++++++++++-
 lisp/erc/erc-button.el  | 16 ++++++++--------
 2 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index ec45dcf..4925c96 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -474,13 +474,39 @@ Currently this is called by `erc-send-input'."
                      nil t))
       (split-string (buffer-string) "\n"))))
 
+(defun erc-forward-word ()
+  "Moves forward one word, ignoring any subword settings.  If no
+subword-mode is active, then this is (forward-word)."
+  (skip-syntax-forward "^w")
+  (> (skip-syntax-forward "w") 0))
+
+(defun erc-word-at-arg-p (pos)
+  "Reports whether the char after a given POS has word syntax.
+If POS is out of range, the value is nil."
+  (let ((c (char-after pos)))
+    (if c
+        (eq ?w (char-syntax c))
+      nil)))
+
+(defun erc-bounds-of-word-at-point ()
+  "Returns the bounds of a word at point, or nil if we're not at
+a word.  If no subword-mode is active, then this
+is (bounds-of-thing-at-point 'word)."
+  (if (or (erc-word-at-arg-p (point))
+          (erc-word-at-arg-p (1- (point))))
+      (save-excursion
+        (let* ((start (progn (skip-syntax-backward "w") (point)))
+               (end   (progn (skip-syntax-forward  "w") (point))))
+          (cons start end)))
+    nil))
+
 ;; Used by CTCP functions
 (defun erc-upcase-first-word (str)
   "Upcase the first word in STR."
   (with-temp-buffer
     (insert str)
     (goto-char (point-min))
-    (upcase-word 1)
+    (upcase-region (point) (progn (erc-forward-word) (point)))
     (buffer-string)))
 
 (defun erc-server-setup-periodical-ping (buffer)
diff --git a/lisp/erc/erc-button.el b/lisp/erc/erc-button.el
index 0e4c709..a59ad22 100644
--- a/lisp/erc/erc-button.el
+++ b/lisp/erc/erc-button.el
@@ -300,14 +300,14 @@ specified by `erc-button-alist'."
     (when (or (eq t form)
               (eval form))
       (goto-char (point-min))
-      (while (forward-word 1)
-        (setq bounds (bounds-of-thing-at-point 'word))
-        (setq word (buffer-substring-no-properties
-                    (car bounds) (cdr bounds)))
-        (when (or (and (erc-server-buffer-p) (erc-get-server-user word))
-                  (and erc-channel-users (erc-get-channel-user word)))
-          (erc-button-add-button (car bounds) (cdr bounds)
-                                 fun t (list word)))))))
+      (while (erc-forward-word)
+        (when (setq bounds (erc-bounds-of-word-at-point))
+          (setq word (buffer-substring-no-properties
+                      (car bounds) (cdr bounds)))
+          (when (or (and (erc-server-buffer-p) (erc-get-server-user word))
+                    (and erc-channel-users (erc-get-channel-user word)))
+            (erc-button-add-button (car bounds) (cdr bounds)
+                                   fun t (list word))))))))
 
 (defun erc-button-add-buttons-1 (regexp entry)
   "Search through the buffer for matches to ENTRY and add buttons."
-- 
2.1.4


  reply	other threads:[~2016-01-09 18:14 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-23  9:19 bug#17558: 24.4.50; global-subword-mode breaks ERC Dima Kogan
2014-05-23 20:51 ` Daniel Colascione
2014-12-31  8:46   ` Dima Kogan
2014-12-31  9:01   ` Dima Kogan
2015-01-01 16:42     ` Stefan Monnier
2015-01-01 21:47       ` Dima Kogan
2015-04-27 20:03       ` Glenn Morris
2015-04-27 22:31         ` Daniel Colascione
2015-04-27 23:24           ` Drew Adams
2015-04-27 23:30             ` Daniel Colascione
2015-04-27 23:59               ` Drew Adams
2015-04-28 16:50           ` Glenn Morris
2015-04-29  1:50             ` Stefan Monnier
2015-04-29  2:31             ` Daniel Colascione
2015-07-15  3:37               ` Dima Kogan
2015-12-26 21:46                 ` Lars Ingebrigtsen
2015-12-27 21:16                   ` Dima Kogan
2015-12-27 21:38                     ` Lars Ingebrigtsen
2016-01-08 18:54                   ` Dima Kogan
2016-01-09  9:04                     ` Lars Magne Ingebrigtsen
2016-01-09 18:14                       ` Dima Kogan [this message]
2016-01-26  8:07                         ` Dima Kogan
2016-02-04  3:21                         ` 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=87twmmhb6s.fsf@secretsauce.net \
    --to=dima@secretsauce.net \
    --cc=17558@debbugs.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).