[Top][All Lists]

[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: Bob Rogers
Subject: Re: comint-insert-input on non-command lines: A trivial fix, a quibble, and a bug
Date: Mon, 8 May 2006 21:55:32 -0400

   From: Nick Roberts <address@hidden>
   Date: Mon, 8 May 2006 16:18:26 +1200

    >    I see now that comint-copy-old-input did indeed copy the whole line but
    >    although the name would not suggest so.
    > What it did depended on the value of comint-use-prompt-regexp.  It
    > relied on the value of the variable comint-get-old-input, whose
    > default value was comint-get-old-input-default.  Here is the
    > emacs-21.3 doc of the latter function:
    >   Default for `comint-get-old-input'.
    >   If `comint-use-prompt-regexp-instead-of-fields' is nil, then either
    >   return the current input field, if point is on an input field, or the
    >   current line, if point is on an output field.
    >   If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then return
    >   the current line with any initial string matching the regexp
    >   `comint-prompt-regexp' removed.
    > `comint-use-prompt-regexp-instead-of-fields' is now called
    > `comint-use-prompt-regexp'.

So this *is* documented behavior.  Is the change in behavior
inadvertent, then?

   There is also a comment by comint-use-prompt-regexp (also present in 21.3):

   ;; Note: If it is decided to purge comint-prompt-regexp from the source
   ;; entirely, searching for uses of this variable will help to identify
   ;; places that need attention.

   I presume use of comint-prompt-regexp preceded the use of fields.
   Perhaps this should be purged as there's no need to use two methods and this
   would reduce the maintenance overhead.

Perhaps, but that doesn't address the original issue, namely that in
comint-mode "C-c RET" is now less useful that it had been.

   From: Miles Bader <address@hidden>
   Date: Mon, 08 May 2006 13:49:19 +0900

   Luc Teirlinck <address@hidden> writes:

   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 . . .

   I'll commit this unless somebody objects.

But it doesn't address the original problem:  "C-c RET" still does
nothing when invoked on an output line.  Please find a solution below
that merges your changes with the guts of the comint-copy-old-input
definition from 21.3, restoring the original behavior.  If that is
satisfactory to everyone, then I will undertake to ensure that all of
the documentation is consistent.

                                        -- Bob

(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* ((input-pos (point))
           (or (marker-position comint-accum-marker)
               (let ((process (get-buffer-process (current-buffer))))
                 (if (not process)
                     (error "Current buffer has no process"))
                 (process-mark process))))
           (if (eq (field-at-pos input-pos) 'input)
               ;; Use the field.
               (field-string-no-properties input-pos)
               ;; No input at INPUT-POS, fall back to the "old input" heuristic.
               (funcall comint-get-old-input))))
    ;; Insert the input, after first deleting any old unsent input at the end.
    (goto-char (point-max))
    (delete-region insertion-point (point))
    (insert string-to-insert)))

(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)

reply via email to

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