开发者

emacs 23.2.1: character-by-character copying from the previous line seems broken

After upgrading to emacs 23.2.1 with Fedora 15 one of my emacs functions is broken and I just can't seem to find the problem. Something has to have changed, but I sure can't find it in the elisp documentation.

I'd开发者_开发技巧 really appreciate any suggestions!

What it should do: Pressing Ctl-hyphen should copy the character above the cursor and move the point ahead by 1.

What it does: Keeps copying the character above without advancing the point. HOWEVER, calling it with "M-x insert-char-from-previous-line" or pressing RightArrow between Ctl-hypens works as it should. Adding (forward-char 1) to the end of the script doesn't help.

(defun insert-char-from-previous-line ()
  "Copy previous line character by character"
   (interactive)
   (previous-line 1)
      (let ((char-above (following-char) ))
      (next-line 1)
   (if (not (char-equal char-above ?\n ))
       (insert char-above))))

(global-set-key [?\C--] 'insert-char-from-previous-line) ;copy char above


I think your getting caught in a goal column issue. You probably should not use next-line/previous-line for this, rather try this:

 (defun insert-char-from-previous-line ()
   "Copy previous line character by character"
   (interactive)
   (let ((curpoint (point))
    (curcolumn (current-column)))
      (forward-line -1)
      (forward-char curcolumn)
      (let ((char-above (following-char) ))
      (goto-char curpoint)
      (if (not (char-equal char-above ?\n ))
     (insert char-above)))))

From the docs on pervious-line:

If you are thinking of using this in a Lisp program, consider using `forward-line' with a negative argument instead. It is usually easier to use and more reliable (no dependence on goal column, etc.).

 (describe-function 'previous-line)


don't move the point for something like this:

(defun i-char (arg)
  (interactive "*p")
  (let ((start (+ (point-at-bol 0)
                  (current-column)))))
  (insert (buffer-substring-no-properties start (+ start arg))))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜