all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* viper-mode: "r <Return>" does not work as expected
@ 2005-04-28  7:32 ` Olaf Dietrich
  2005-04-28 18:44   ` Kevin Rodgers
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Olaf Dietrich @ 2005-04-28  7:32 UTC (permalink / raw)


I tried this in all viper-mode levels (GNU Emacs 21.4.1, i386 Linux):

Inserting a new line break in an existing line by "r <Return>"
(more exactly: replacing the current character by a newline)
does not work; instead, '^M' appears as replacement text.

(The alternative "r C-j" _does_ work, but is not what my fingers
are used to do in vi.)

Is it possible to make "r <Return>" work as well? Is this a known
limitation or bug? (Well, yes, it is known, I found the post

  From: eesti@corp.earthlink.net
  Subject: Emacs VIPER mode: RETURN shows up as ^M after replace
  Newsgroups: gnu.emacs.help
  Message-ID: <%NFK8.379$se.11@newsread1.prod.itd.earthlink.net>
  Date: Mon, 03 Jun 2002 08:29:47 GMT

but I haven't found any suggestions how to change this behavior.)

Thanks in advance,
Olaf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: viper-mode: "r <Return>" does not work as expected
  2005-04-28  7:32 ` viper-mode: "r <Return>" does not work as expected Olaf Dietrich
@ 2005-04-28 18:44   ` Kevin Rodgers
       [not found]   ` <mailman.3342.1114714165.2895.help-gnu-emacs@gnu.org>
  2005-05-06  7:27   ` Olaf Dietrich
  2 siblings, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2005-04-28 18:44 UTC (permalink / raw)


Olaf Dietrich wrote:
> I tried this in all viper-mode levels (GNU Emacs 21.4.1, i386 Linux):
> 
> Inserting a new line break in an existing line by "r <Return>"
> (more exactly: replacing the current character by a newline)
> does not work; instead, '^M' appears as replacement text.
> 
> (The alternative "r C-j" _does_ work, but is not what my fingers
> are used to do in vi.)
> 
> Is it possible to make "r <Return>" work as well? Is this a known
> limitation or bug? (Well, yes, it is known, I found the post
> 
>   From: eesti@corp.earthlink.net
>   Subject: Emacs VIPER mode: RETURN shows up as ^M after replace
>   Newsgroups: gnu.emacs.help
>   Message-ID: <%NFK8.379$se.11@newsread1.prod.itd.earthlink.net>
>   Date: Mon, 03 Jun 2002 08:29:47 GMT
> 
> but I haven't found any suggestions how to change this behavior.)

The version of viper-cmd.el distributed with Emacs 21.3 has this snippet
in the viper-replace-char-subr function:

       (if (eq char ?\C-m) (setq char ?\n))

So perhaps you're using an old version of viper -- what do `M-x
locate-library RET viper' and `M-x list-load-path-shadows' tell
you?

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: viper-mode: "r <Return>" does not work as expected
       [not found]   ` <mailman.3342.1114714165.2895.help-gnu-emacs@gnu.org>
@ 2005-04-29  7:28     ` Olaf Dietrich
  2005-04-29 12:34       ` Olaf Dietrich
  0 siblings, 1 reply; 6+ messages in thread
From: Olaf Dietrich @ 2005-04-29  7:28 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com>:
> Olaf Dietrich wrote:
>> 
>> Inserting a new line break in an existing line by "r <Return>"
>> (more exactly: replacing the current character by a newline)
>> does not work; instead, '^M' appears as replacement text.
>> 
>> (The alternative "r C-j" _does_ work, but is not what my fingers
>> are used to do in vi.)
> 
> The version of viper-cmd.el distributed with Emacs 21.3 has this snippet
> in the viper-replace-char-subr function:
> 
>       (if (eq char ?\C-m) (setq char ?\n))

This line is in my viper-cmd.el as well:

| (defun viper-replace-char-subr (com arg)
|   (let ((inhibit-quit t)
|         char)
|     (viper-set-complex-command-for-undo)
|     (or (eq viper-intermediate-command 'viper-repeat)
|         (viper-special-read-and-insert-char))
| 
|       (if (eq char ?\C-m) (setq char ?\n))
...

viper.el says:

| (defconst viper-version "3.11.1 of September 9, 2001"
|   "The current version of Viper")


> So perhaps you're using an old version of viper --
> what do `M-x locate-library RET viper'

| Library is file ..../emacs/21.4/lisp/emulation/viper.elc

(The path appears correct.)

> and `M-x list-load-path-shadows' tell you?

| No Emacs Lisp load-path shadowings were found

Does this make any sense?


Thanks,
Olaf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: viper-mode: "r <Return>" does not work as expected
  2005-04-29  7:28     ` Olaf Dietrich
@ 2005-04-29 12:34       ` Olaf Dietrich
  2005-04-29 18:55         ` Kevin Rodgers
  0 siblings, 1 reply; 6+ messages in thread
From: Olaf Dietrich @ 2005-04-29 12:34 UTC (permalink / raw)


Olaf Dietrich <odt@dtrx.de>:
> Kevin Rodgers <ihs_4664@yahoo.com>:
>> Olaf Dietrich wrote:
>>> 
>>> Inserting a new line break in an existing line by "r <Return>"
>>> (more exactly: replacing the current character by a newline)
>>> does not work; instead, '^M' appears as replacement text.
>>> 
>> The version of viper-cmd.el distributed with Emacs 21.3 has this snippet
>> in the viper-replace-char-subr function:
>> 
>>       (if (eq char ?\C-m) (setq char ?\n))
> 
> This line is in my viper-cmd.el as well:

I've just played a little bit with viper-cmd.el; the original
function is

| (defun viper-replace-char-subr (com arg)
|   (let ((inhibit-quit t)
|         char)
|     (viper-set-complex-command-for-undo)
|     (or (eq viper-intermediate-command 'viper-repeat)
|         (viper-special-read-and-insert-char))
| 
|       (if (eq char ?\C-m) (setq char ?\n))
| 
|       (delete-char 1 t)
| 
|       (setq char (if com viper-d-char (viper-char-at-pos 'backward)))
|       (if com (insert char))
| 
|       (setq viper-d-char char)
| 
|       (viper-loop (1- (if (> arg 0) arg (- arg)))
|                   (delete-char 1 t)
|                   (insert char))
| 
|       (viper-adjust-undo)
|       (backward-char arg)
|       ))

Since I have never work with (emacs) lisp before, I don't
know whether my attempts made any sense, but if I (simple
enough) changed e.g. "(delete-char 1 t)" to "(delete-char 3 t)"
than 3 instead of 1 character were replaced by a single new
one. But I wasn't able to find out whether the line

|       (if (eq char ?\C-m) (setq char ?\n))

is executed at all. Adding something like "(insert ?A)"
inserted an additional "A", but I wasn't able to change
char by e.g. "(setq char ?A)".

Any ideas what to try next?

Olaf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: viper-mode: "r <Return>" does not work as expected
  2005-04-29 12:34       ` Olaf Dietrich
@ 2005-04-29 18:55         ` Kevin Rodgers
  0 siblings, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2005-04-29 18:55 UTC (permalink / raw)


Olaf Dietrich wrote:
 > I've just played a little bit with viper-cmd.el; the original
 > function is
 >
 > | (defun viper-replace-char-subr (com arg)
 > |   (let ((inhibit-quit t)
 > |         char)
 > |     (viper-set-complex-command-for-undo)
 > |     (or (eq viper-intermediate-command 'viper-repeat)
 > |         (viper-special-read-and-insert-char))
 > |
 > |       (if (eq char ?\C-m) (setq char ?\n))
 > |
 > |       (delete-char 1 t)
 > |
 > |       (setq char (if com viper-d-char (viper-char-at-pos 'backward)))
 > |       (if com (insert char))
 > |
 > |       (setq viper-d-char char)
 > |
 > |       (viper-loop (1- (if (> arg 0) arg (- arg)))
 > |                   (delete-char 1 t)
 > |                   (insert char))
 > |
 > |       (viper-adjust-undo)
 > |       (backward-char arg)
 > |       ))
 >
 > Since I have never work with (emacs) lisp before, I don't
 > know whether my attempts made any sense, but if I (simple
 > enough) changed e.g. "(delete-char 1 t)" to "(delete-char 3 t)"
 > than 3 instead of 1 character were replaced by a single new
 > one. But I wasn't able to find out whether the line
 >
 > |       (if (eq char ?\C-m) (setq char ?\n))
 >
 > is executed at all. Adding something like "(insert ?A)"
 > inserted an additional "A", but I wasn't able to change
 > char by e.g. "(setq char ?A)".
 >
 > Any ideas what to try next?

Report it as a bug.  I have many years of Emacs Lisp experience, and
I've been playing with that function today, too.  And it is badly
broken.

The first problem is that the (if (eq char ?\C-m) (setq char ?\n)) form
occurs before char has been set.  The second problem is that when that
form is evaluated and char is reset, it has already been inserted; but
no attempt is made to undo that and re-insert the proper newline
character.

It would be a lot easier to fix if viper was properly designed i.e. one
function to read the character and one function to insert it instead of
combining those functions into viper-special-read-and-insert-char.

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: viper-mode: "r <Return>" does not work as expected
  2005-04-28  7:32 ` viper-mode: "r <Return>" does not work as expected Olaf Dietrich
  2005-04-28 18:44   ` Kevin Rodgers
       [not found]   ` <mailman.3342.1114714165.2895.help-gnu-emacs@gnu.org>
@ 2005-05-06  7:27   ` Olaf Dietrich
  2 siblings, 0 replies; 6+ messages in thread
From: Olaf Dietrich @ 2005-05-06  7:27 UTC (permalink / raw)


Olaf Dietrich <odt@dtrx.de>:
> 
> Inserting a new line break in an existing line by "r <Return>"
> (more exactly: replacing the current character by a newline)
> does not work; instead, '^M' appears as replacement text.

By comparing the current CVS version of viper (viper-version "3.11.4
of February 19, 2005") to the one distributed with Emacs 21.4.1
(viper-version "3.11.1 of September 9, 2001"), I found the following
patch for viper-cmd.el the makes "r <Return>" work (only the fourth
insertion seems to be necessary to remove the described problem,
but all four seem to deal with similar ^M stuff).

Thanks to Kevin Rodgers and to Michael Kifer for their help,
Olaf


(crossposted to gnu.emacs.help and comp.emacs;
followups to: gnu.emacs.help;
and apologies in advance if a former version of this post (stupidly
cross-posted to a moderated group) should pop up here)


--- emacs-21.4/lisp/emulation/viper-cmd.el	2002-06-10 15:05:03.000000000 +0200
+++ viper-cmd.el	2005-05-03 10:22:57.860007000 +0200
@@ -789,6 +789,13 @@
 		 ;; The next 2 cmds are intended to prevent the input method
 		 ;; from swallowing ^M, ^Q and other special characters
 		 (setq ch (read-char))
+;; start copy from viper 3.11.4 (2005-02-19)
+		 ;; replace ^M with the newline
+		 (if (eq ch ?\C-m) (setq ch ?\n))
+		 ;; Make sure ^V and ^Q work as quotation chars
+		 (if (memq ch '(?\C-v ?\C-q))
+		     (setq ch (read-char)))
+;; end copy from viper 3.11.4 (2005-02-19)
 		 (viper-set-unread-command-events ch)
 		 (quail-input-method nil)
 
@@ -806,6 +813,13 @@
 	       ;; quail-input-method
 	       (let (unread-command-events)
 		 (setq ch (read-char))
+;; start copy from viper 3.11.4 (2005-02-19)
+		 ;; replace ^M with the newline
+		 (if (eq ch ?\C-m) (setq ch ?\n))
+		 ;; Make sure ^V and ^Q work as quotation chars
+		 (if (memq ch '(?\C-v ?\C-q))
+		     (setq ch (read-char)))
+;; end copy from viper 3.11.4 (2005-02-19)
 		 (viper-set-unread-command-events ch)
 		 (quail-start-translation nil)
 
@@ -818,9 +832,24 @@
 		 ))
 	      ((and (boundp 'iso-accents-mode) iso-accents-mode)
 	       (setq ch (aref (read-key-sequence nil) 0))
+;; start copy from viper 3.11.4 (2005-02-19)
+	       ;; replace ^M with the newline
+	       (if (eq ch ?\C-m) (setq ch ?\n))
+	       ;; Make sure ^V and ^Q work as quotation chars
+	       (if (memq ch '(?\C-v ?\C-q))
+		   (setq ch (aref (read-key-sequence nil) 0)))
+;; end copy from viper 3.11.4 (2005-02-19)
 	       (insert ch))
 	      (t
 	       (setq ch (read-char))
+;; the following 7 lines make "r <Ret>" work as expected
+;; start copy from viper 3.11.4 (2005-02-19)
+	       ;; replace ^M with the newline
+	       (if (eq ch ?\C-m) (setq ch ?\n))
+	       ;; Make sure ^V and ^Q work as quotation chars
+	       (if (memq ch '(?\C-v ?\C-q))
+		   (setq ch (read-char)))
+;; end copy from viper 3.11.4 (2005-02-19)
 	       (insert ch))
 	      )
 	(setq last-command-event
@@ -2554,7 +2583,9 @@
     (or (eq viper-intermediate-command 'viper-repeat)
 	(viper-special-read-and-insert-char))
 
-      (if (eq char ?\C-m) (setq char ?\n))
+;; start copy from viper 3.11.4 (2005-02-19)
+;;      (if (eq char ?\C-m) (setq char ?\n))
+;; end copy from viper 3.11.4 (2005-02-19)
 
       (delete-char 1 t)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-05-06  7:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <d4861u$28v$1@wsc10.lrz-muenchen.de>
2005-04-28  7:32 ` viper-mode: "r <Return>" does not work as expected Olaf Dietrich
2005-04-28 18:44   ` Kevin Rodgers
     [not found]   ` <mailman.3342.1114714165.2895.help-gnu-emacs@gnu.org>
2005-04-29  7:28     ` Olaf Dietrich
2005-04-29 12:34       ` Olaf Dietrich
2005-04-29 18:55         ` Kevin Rodgers
2005-05-06  7:27   ` Olaf Dietrich

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.