home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / editors / emacs / console.el < prev    next >
Encoding:
Text File  |  1993-11-17  |  4.2 KB  |  142 lines

  1. ;;; console.el --- define key sequences for Linux console
  2.  
  3. ;; Author: Robert Sanders, gt8134b@prism.gatech.edu
  4. ;; Keywords: terminals, Linux, console
  5. ;; $Date: 1993/10/14 17:08:20 $
  6. ;; $Source: /usr/local/lib/emacs/site-lisp/RCS/console.el,v $
  7. ;; $Revision: 1.4 $
  8. ;; $State: Exp $
  9. ;;
  10.  
  11. ;;; Commentary:
  12.  
  13. ;; Uses the Emacs 19 terminal initialization features --- won't work 
  14. ;; with Emacs 18
  15.  
  16. ;; specifically modified for the Linux console as of version 0.99pl10
  17. ;; ...overrides the termcap defaults
  18.  
  19. ;;; Code:
  20.  
  21. ;;; CSI sequences - those that start with "\e[".
  22. ;; Termcap or terminfo should set some of these up automatically
  23. ;; however, as no distribution seems to have the termcap set up right,
  24. ;; we'll define the keys regardless...
  25.  
  26. ;; you can comment out any of these to get the termcap
  27. ;; defaults
  28.  
  29. (defun set-fkey-map-list (pairlist) "Set function keymap from a list.
  30. The list format is ( (string key) ... )"
  31.   (if pairlist
  32.       (let ((pair (car pairlist)))
  33.     (define-key function-key-map (car pair) (car (cdr pair)))
  34.     (set-fkey-map-list (cdr pairlist)))))
  35.  
  36. (set-fkey-map-list '( ("\e[A" [f1])
  37.               ("\e[B" [down])
  38.               ("\e[A" [up])
  39.               ("\e[B" [down])
  40.               ("\e[C" [right])
  41.               ("\e[D" [left])
  42.               ("\e[5~" [prior])
  43.               ("\e[6~" [next])
  44.               ("\e[2~" [insert])
  45.               ("\e[1~" [home])
  46.               ("\e[4~" [end])
  47.               ("\e[3~" [delete])
  48.               ("\e[[A" [f1])
  49.               ("\e[[B" [f2])
  50.               ("\e[[C" [f3])
  51.               ("\e[[D" [f4])
  52.               ("\e[[E" [f5])
  53.               ("\e[17~" [f6])
  54.               ("\e[18~" [f7])
  55.               ("\e[19~" [f8])
  56.               ("\e[20~" [f9])
  57.               ("\e[21~" [f10])
  58.               ("\e[23~" [f11])
  59.               ("\e[24~" [f12])))
  60.  
  61. (define-key function-key-map "\C-\\" [print])   ; PrintScreen key
  62.  
  63. ;;; SS3 sequences - those that start with "\eO".
  64.  
  65. ;; Terminfo might set these
  66. (defun linux-numlock-off ()
  67.   "Set Linux console keypad to simulated NumLock-off mode"
  68.   (interactive)
  69.   (setq mode-line-numlock-string "")
  70.   (force-mode-line-update)
  71.   (set-fkey-map-list '( ("\eOp" [kp-0]) ; kp0
  72.             ("\eOq" [kp-1]) ; kp1
  73.             ("\eOr" [kp-2]) ; kp2
  74.             ("\eOs" [kp-3]) ; kp3
  75.             ("\eOt" [kp-4]) ; kp4
  76.             ("\eOu" [kp-5]) ; kp5
  77.             ("\eOv" [kp-6]) ; kp6
  78.             ("\eOw" [kp-7]) ; kp7
  79.             ("\eOx" [kp-8]) ; kp8
  80.             ("\eOy" [kp-9]) ; kp9
  81.             ("\eOl" [kp-add])
  82.             ("\eOS" [kp-subtract])
  83.             ("\eOR" [kp-multiply])
  84.             ("\eOQ" [kp-divide])
  85.             ("\eOM" [kp-enter])
  86.             ("\eOn" [kp-decimal]))))
  87.              
  88. (defun linux-numlock-on () 
  89.   "Set Linux console keypad to simulated NumLock-on mode"
  90.   (interactive)
  91.   (setq mode-line-numlock-string numlock-string)
  92.   (force-mode-line-update)
  93.   (set-fkey-map-list '( ("\eOp" [?0]) ; 0
  94.                ("\eOq" [?1]) ; 1
  95.                ("\eOr" [?2]) ; 2
  96.                ("\eOs" [?3]) ; 3
  97.                ("\eOt" [?4]) ; 4
  98.                ("\eOu" [?5]) ; 5
  99.                ("\eOv" [?6]) ; 6
  100.                ("\eOw" [?7]) ; 7
  101.                ("\eOx" [?8]) ; 8
  102.                ("\eOy" [?9]) ; 9
  103.                ("\eOl" [?+])
  104.                ("\eOS" [?-])
  105.                ("\eOR" [?*])
  106.                ("\eOQ" [?/])
  107.                ("\eOM" [?\C-j])
  108.                ("\eOn" [?.]))))
  109.  
  110. ;; these are the strings the Linux console keypad transmits when
  111. ;; in application mode.  Emacs manually turns keypad mode on
  112. ;; at the bottom of this file.
  113.  
  114. (defvar numlock-string "NumLock"
  115.   "String which the mode-line should display if Linux console simulated
  116. NumLock is on")
  117. (defvar linux-console-numlock nil "State of simulated keypad NumLock")
  118.  
  119. (defvar mode-line-numlock-string "")
  120. (defun do-linux-console-numlock () "Handle the keypad NumLock key."
  121.   (interactive)
  122.   (if (setq linux-console-numlock (not linux-console-numlock))
  123.       (linux-numlock-on)
  124.     (linux-numlock-off)))
  125.  
  126. ;; trim the last element off the end, which should be the "-%-" 
  127. ;; infinite row of dashes format, and add the numlock string
  128. (setcdr (nthcdr (- (length mode-line-format) 2) mode-line-format) 
  129.     '("---" mode-line-numlock-string "-%-"))
  130. (define-key function-key-map "\eOP" [kp-numlock])
  131.  
  132. ;; put keypad into application mode so we can differentiate between
  133. ;; keypad keys and normal keys...we use the functions 
  134. ;; linux-numlock-{on,off} to simulate the keypad functionality.
  135. ;; we can fudge the mode-line, but we still can't change the LED :-(
  136.  
  137. (global-set-key [kp-numlock] 'do-linux-console-numlock)
  138. (linux-numlock-off)
  139. (send-string-to-terminal "\e=")
  140.  
  141. ;;; console.el ends here
  142.