emacs-devel
[Top][All Lists]
Advanced

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

Re: comint-insert-input on non-command lines: A trivial fix, a quibble,


From: Miles Bader
Subject: Re: comint-insert-input on non-command lines: A trivial fix, a quibble, and a bug
Date: Mon, 08 May 2006 13:49:19 +0900

Luc Teirlinck <address@hidden> writes:
> On closer inspection, what seems to cause this bug is that
> comint-insert-input contains:
>
>     (if (not (eq (get-char-property (point) 'field) 'input))
>     ;; No input at POS, fall back to the global definition.
>
> If comint-use-prompt-regexp is non-nil, then there are no field
> properties, so, despite what the comment claims, that condition does
> _not_ assure that there is no input at POS.

BTW, that function's use of fields is not well written.

Also, it uses `posn-set-point' _after_ getting the value of (point),
which doesn't make any sense to me.

The following seems to fix both problems (note new helper function following):


   (defun comint-insert-input (&optional event)
     "In a Comint buffer, set the current input to the previous input at point."
     ;; This doesn't use "e" because it is supposed to work
     ;; for events without parameters.
     (interactive (list last-input-event))
     (when event
       (posn-set-point (event-end event)))
     (let ((pos (point)))
       (if (not (eq (field-at-pos pos) 'input))
           ;; No input at POS, fall back to the global definition.
           (let* ((keys (this-command-keys))
                  (last-key (and (vectorp keys) (aref keys (1- (length keys)))))
                  (fun (and last-key (lookup-key global-map (vector 
last-key)))))
             (goto-char pos)
             (and fun (call-interactively fun)))
         (setq pos (point))
         ;; There's previous input at POS, insert it at the end of the buffer.
         (goto-char (point-max))
         ;; First delete any old unsent input at the end
         (delete-region
          (or (marker-position comint-accum-marker)
              (process-mark (get-buffer-process (current-buffer))))
          (point))
         ;; Insert the input at point
         (insert (field-string-no-properties pos)))))

   (defun field-at-pos (pos)
     "Return the field at position POS, taking stickiness etc into account"
     (let ((raw-field (get-char-property (field-beginning pos) 'field)))
       (if (eq raw-field 'boundary)
           (get-char-property (1- (field-end pos)) 'field)
         raw-field)))


I'll commit this unless somebody objects.


-Miles
-- 
"Though they may have different meanings, the cries of 'Yeeeee-haw!' and
 'Allahu akbar!' are, in spirit, not actually all that different."




reply via email to

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