emacs-devel
[Top][All Lists]
Advanced

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

Changes to make the C-x @ commands work with function keys


From: Al Petrofsky
Subject: Changes to make the C-x @ commands work with function keys
Date: Mon, 11 Feb 2002 17:38:08 -0800

Below are some changes that make the C-x @ commands work with function
keys.  This also makes them work with each other, i.e. C-x @ c C-x @ m
% will run query-replace-regexp.  These aren't very convenient to
type, but if you can program your tty to send these C-x @ sequences
for you, then all the M-home, M-end, C-next, etc.. keybindings will be
conveniently available.

I simplified (and pessimized) the event-apply-modifier function,
rather than try to fix the bugs it had when mixing modifiers (e.g.,
adding control to M-a and adding meta to C-a returned different
results.)

-al


(defun read-function-mapped-event ()
  "Read an event or function key.
Like `read-event', but input is first translated according to
`function-key-map' and `key-translation-map', so that a function key
event may be composed."
  (let ((event (read-event)))
    (if (consp event)
        ;; Don't touch mouse events.
        event
      ;; Otherwise, block out the maps that are used after
      ;; key-translation-map, and call read-key-sequence.
      (push event unread-command-events)
      (let ((overriding-local-map (make-sparse-keymap))
            (global (current-global-map)))
        (unwind-protect
            (progn (use-global-map (make-sparse-keymap))
                   (let ((vec (read-key-sequence-vector nil)))
                     (if (> (length vec) 1)
                         (setq unread-command-events
                               (cdr (append vec unread-command-events))))
                     (aref vec 0)))
          (use-global-map global))))))


;; These functions -- which are not commands -- each add one modifier
;; to the following event.

(defun event-apply-alt-modifier (ignore-prompt)
  "Add the Alt modifier to the following event.
For example, type \\[event-apply-alt-modifier] & to enter Alt-&."
  `[,(event-apply-modifier (read-function-mapped-event) 'alt)])

(defun event-apply-super-modifier (ignore-prompt)
  "Add the Super modifier to the following event.
For example, type \\[event-apply-super-modifier] & to enter Super-&."
  `[,(event-apply-modifier (read-function-mapped-event) 'super)])

(defun event-apply-hyper-modifier (ignore-prompt)
  "Add the Hyper modifier to the following event.
For example, type \\[event-apply-hyper-modifier] & to enter Hyper-&."
  `[,(event-apply-modifier (read-function-mapped-event) 'hyper)])

(defun event-apply-shift-modifier (ignore-prompt)
  "Add the Shift modifier to the following event.
For example, type \\[event-apply-shift-modifier] & to enter Shift-&."
  `[,(event-apply-modifier (read-function-mapped-event) 'shift)])

(defun event-apply-control-modifier (ignore-prompt)
  "Add the Control modifier to the following event.
For example, type \\[event-apply-control-modifier] & to enter Control-&."
  `[,(event-apply-modifier (read-function-mapped-event) 'control)])

(defun event-apply-meta-modifier (ignore-prompt)
  "Add the Meta modifier to the following event.
For example, type \\[event-apply-meta-modifier] & to enter Meta-&."
  `[,(event-apply-modifier (read-function-mapped-event) 'meta)])



(defun event-apply-modifier (event modifier)
  "Apply a modifier flag to event EVENT.
MODIFIER is the name of the modifier, as a symbol."
  (let ((modified (event-convert-list `(,modifier
                                        ,@(delq 'click (event-modifiers event))
                                        ,(event-basic-type event)))))
    (if (consp event)
        (cons modified (cdr event))
      modified)))



reply via email to

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