smart-comint-up
Wright, Kevin
kevin.wright at pioneer.com
Wed Oct 23 22:23:24 CEST 2002
All,
I just found a very useful bit of .emacs code from Tudor Hulubei and thought
I would share it here. When the point is at the inferior-ess prompt, the up
arrow key recalls the previous item in the history list. Otherwise, the
up-arrow key behaves normally.
Cheers,
Kevin Wright
;;; In comint modes the [up] and [down] keys will be mapped to this
;;; two functions and will use the history only when the point is at
;;; the command line. In any other place the [up] and [down] keys
;;; will behave as usual, i.e. move the point to the previous or next
;;; line. Smart, eh? Tudor Hulubei
(defun smart-comint-up ()
"Implement the behaviour of the up arrow key in comint mode. At
the end of buffer, do comint-previous-input, otherwise just move in
the buffer."
(interactive)
(let ((previous-region-status (if xemacs-flag (region-active-p) nil)))
(if (= (point) (point-max))
(comint-previous-input 1)
(previous-line 1))
(when previous-region-status
(activate-region))))
(defun smart-comint-down ()
"Implement the behaviour of the down arrow key in comint mode. At
the end of buffer, do comint-next-input, otherwise just move in the
buffer."
(interactive)
(let ((previous-region-status (if xemacs-flag (region-active-p) nil)))
(if (= (point) (point-max))
(comint-next-input 1)
(forward-line 1))
(when previous-region-status
(activate-region))))
;;; Set up the smart comint arrow keys. See smart-comint-up/down.
(defun setup-smart-comint-arrow-keys ()
"Set up the smart comint arrow keys. See smart-comint-up/down."
(local-set-key [up] 'smart-comint-up)
(local-set-key [down] 'smart-comint-down))
;;; This hook will be called when entering several `comint' modes:
;;; 'gud/gdb', `shell', `term', `ielm', `tex-shell', 'inferior-ess'.
(mapcar #'(lambda (hook) (add-hook hook 'setup-smart-comint-arrow-keys))
(list 'gdb-mode-hook 'shell-mode-hook 'term-mode-hook
'ielm-mode-hook 'tex-shell-hook 'inferior-ess-mode-hook))
This communication is for use by the intended recipient and contains
information that may be privileged, confidential or copyrighted under
applicable law. If you are not the intended recipient, you are hereby
formally notified that any use, copying or distribution of this e-mail,
in whole or in part, is strictly prohibited. Please notify the sender
by return e-mail and delete this e-mail from your system. Unless
explicitly and conspicuously designated as "E-Contract Intended",
this e-mail does not constitute a contract offer, a contract amendment,
or an acceptance of a contract offer. This e-mail does not constitute
a consent to the use of sender's contact information for direct marketing
purposes or for transfers of data to third parties.
Francais Deutsch Italiano Espanol Portugues Japanese Chinese Korean
http://www.DuPont.com/corp/email_disclaimer.html
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
ess-help mailing list -- To (un)subscribe, send
subscribe or unsubscribe
(in the "body", not the subject !) To: ess-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the ESS-help
mailing list