[comp.emacs] global-set-key in .emacs

jwg1@bunny.UUCP (James W. Gish) (09/25/87)

I'm a new user of GNU Emacs.  It is quite different than Prime EMACS which is
what I'm used to.  I'm attempting to use global-set-key in my .emacs file but
it acts like the default bindings are being set after the .emacs file is
loaded, so my bindings never take effect.

How do I fix this ? (We're using version 18.33.1)

Thanks

-- 
Jim Gish
GTE Laboratories, Inc., Waltham, MA
CSNET: jwg1@gte-labs    UUCP:  ..!harvard!bunny!jwg1

lius@nucsrl.UUCP (09/27/87)

>I'm attempting to use global-set-key in my .emacs file but
>it acts like the default bindings are being set after the .emacs file is
>loaded, so my bindings never take effect.

It is right.
Emacs's loading sequences are: 

  ~/.emacs => emacs default files 
           => term-setup-hook 
           => files under option "-l"

Therefore, you may fix it with the following two methods:
1. Create your initialization file, saying "init.el".
Do one of the following steps:
2. Create an alias for emacs, such as
   alias emacs 'emacs \!* -l init'   (you may insert it in ~/.login)
or
2'. Insert the following code in your ".emacs"

    (setq term-setup-hook 
      '(lambda () 
	 (load "init")))

Both 2 and 2' work because init.el will be loaded after 
all default files have been loaded by emacs.

Sying-Syang Liu
Dept. of EECS, Northwestern University
UUCP: {gargoyle,ihnp4,chinet}!nucsrl!lius
ARPA/CSNet: lius@EECS.NWU.Edu

mroz@moose.steinmetz (peter a mroz) (09/27/87)

In article <4950@bunny.UUCP> jwg1@bunny.UUCP (James W. Gish) writes:
>I'm attempting to use global-set-key in my .emacs file but
>it acts like the default bindings are being set after the .emacs file is
>loaded, so my bindings never take effect.
>
>How do I fix this ? (We're using version 18.33.1)
>

You have to set the variable TERM-FILE-PREFIX to NIL so that emacs
doesn't override your global-set-keys.  For an example, I've appended
my .emacs file to this article.  The first thing it does is load the
terminal dependent stuff.  THEN it loads my stuff to override anything
I didn't want.  

----------snip----------snip----------snip----------snip----------snip---------
; useful Emacs variable settings

; Inhibit startup message
(setq inhibit-startup-message t)

; Get the terminal type
(defvar term-type (getenv "TERM")
  "variable for the current terminal type")

;; Yanked from emacs startup.el file
;; Load library for our terminal type.
;; User init file can set term-file-prefix to nil to prevent this.
(and term-file-prefix (not noninteractive)
     (load (if window-system
    	   (concat term-file-prefix
    		   (symbol-name window-system)
    		   "-win")
    	   (concat term-file-prefix
    		   (substring term-type 0
    			      (string-match "-" term-type))))
	   t t))

; Then prevent that code from being reexecuted by startup.el by setting
; term-file-prefix to nil:
(setq term-file-prefix nil)

; define my own macros for +line and -line
(defun plus-line (arg)
  "scrolls up 4 lines"
  (interactive "p")
  (if (eq arg 1) (setq arg 4))
  (scroll-up arg)
  )
(defun minus-line (arg)
  "scrolls down 4 lines"
  (interactive "p")
  (if (eq arg 1) (setq arg 4))
  (scroll-down arg)
  )

; Define some useful keypad bindings for a vt100

(if ( or (string= term-type "vt100")
	 (string= term-type "4107")
	 (string= term-type "kermit")
	 (string= term-type "vt100-80"))
    (progn
   ; disable default binding of esc [
      (global-unset-key "\e[")
; VT100 arrow keys
      (global-set-key "\e[A" 'previous-line)
      (global-set-key "\e[B" 'next-line)
      (global-set-key "\e[C" 'forward-char)
      (global-set-key "\e[D" 'backward-char)
      (global-set-key "\eOA" 'previous-line)
      (global-set-key "\eOB" 'next-line)
      (global-set-key "\eOC" 'forward-char)
      (global-set-key "\eOD" 'backward-char)
; PF1 is replace-string, and PF2 is query replace
      (global-set-key "\eOP" 'replace-string)
      (global-set-key "\eOQ" 'query-replace)
; PF3 and PF4 are backward and forward-word
      (global-set-key "\eOR" 'backward-word)
      (global-set-key "\eOS" 'forward-word)
; NP 7 and 8 are Ined-like -page and +page 
      (global-set-key "\eOx" 'scroll-up)
      (global-set-key "\eOw" 'scroll-down)
; NP 9 and - are -line and +line 
      (global-set-key "\eOy" 'minus-line)
      (global-set-key "\eOm" 'plus-line)
; NP 4 and 5 move to the beginning and end of the buffer
      (global-set-key "\eOt" 'beginning-of-buffer)
      (global-set-key "\eOu" 'end-of-buffer)
; NP 6 splits the current window in half
      (global-set-key "\eOv" 'split-window)
; NP 1 deletes the next word
      (global-set-key "\eOq" 'kill-word)
; NP 2 kills a line
      (global-set-key "\eOr" 'kill-line)
; NP 3 undos previous changes
      (global-set-key "\eOs" 'advertised-undo)
; Delete character is NP 0
      (global-set-key "\eOp" 'delete-char)
; The . key toggles overwrite mode
      (global-set-key "\eOn" 'overwrite-mode)
; Next window (^X-n) is bound to NP , key
      (global-set-key "\eOl" 'other-window)
; Execute extended command is the NP ENTER key
      (global-set-key "\eOM" 'execute-extended-command)

; Set the ' key to be the same as escape, because it's in a better position
; on a VT220 and my IBM AT
      (global-set-key "`" 'ESC-prefix)
      )
  )

; My keypad bindings, which are based partially on INED, are the 
; following (num keypad key (kermit key)):
;  -----------------------------------------------------------------
;  |PF1 (F1)       |PF2 (F2)       |PF3 (F3)       |PF4 (F4)       |
;  |               |               |               |               |
;  |replace-string |query-replace  |backward-word  |forward-word   |
;  |---------------+---------------+---------------+---------------|
;  |7  (F5)        |8  (F6)        |9  (F7)        |-  (F8)        |
;  |               |               |               |               |
;  |scroll-down    |scroll-up      |minus-line     |plus-line      |
;  |---------------+---------------+---------------+---------------|
;  |4  (F9)        |5  (F10)       |6 (S-F1)       |, (S-F2)       |
;  |beginning-of-  |               |               |               |
;  |buffer         |end-of-buffer  |split-window   |other-window   |
;  |---------------+---------------+---------------+---------------|
;  |1 (S-F3)       |2 (S-F4)       |3 (S-F5)       |Enter (S-F6)   |
;  |               |               |               |               |
;  |kill-word      |kill-line      |advertised-undo|               |
;  |---------------+---------------+---------------|               | 
;  |0 (S-F7)                       |. (S-F8)       |execute-       |
;  |                               |               |extended-      |
;  |delete-char                    |overwrite-mode |command        |
;  -----------------------------------------------------------------

(global-set-key "\e\\" 'fixup-whitespace)

(define-key ctl-x-map "t" 'display-time)

; Make tabs in a C program real tabs if they're not starting from column 1
(setq c-tab-always-indent nil)

; Start things off with something from Zippy
(yow nil t)

(put 'eval-expression 'disabled nil)

; Add some file extensions to automatically change the emacs mode
(setq auto-mode-alist
      (append auto-mode-alist '(("\\.lsp"   . lisp-mode)
				("\\.emacs" . emacs-lisp-mode)
				("\\.n"     . nroff-mode)
				("\\.for"   . fortran-mode))))
----------snip----------snip----------snip----------snip----------snip---------
Peter Mroz
General Electric			| ARPA: mroz@ge-crd.arpa
Corporate Research and Development	| UUCP: mroz@moose.steinmetz.ge.com
PO Box 8, 37-2081			| clever saying stuck in here
Schenectady, NY 12301			| 518-387-6021