help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: viper-mode: "r <Return>" does not work as expected


From: Kevin Rodgers
Subject: Re: viper-mode: "r <Return>" does not work as expected
Date: Fri, 29 Apr 2005 12:55:08 -0600
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]