gnu-emacs-sources
[Top][All Lists]
Advanced

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

setup-keys.el - custom key bindings


From: Drew Adams
Subject: setup-keys.el - custom key bindings
Date: Tue, 16 Jan 2001 21:35:20 -0500

;;; setup-keys.el --- Some key bindings.
;; 
;; Filename: setup-keys.el
;; Description: Some key bindings.
;; Author: Drew Adams
;; Maintainer: Drew Adams
;; Copyright (C) 1999-2001, Drew Adams, all rights reserved.
;; Created: Fri Apr  2 12:34:20 1999
;; Version: $Id: setup-keys.el,v 1.6 2001/01/09 22:16:56 dadams Exp $
;; Last-Updated: Tue Jan  9 14:16:47 2001
;;           By: dadams
;;     Update #: 274
;; Keywords: mouse, local, keyboard
;; Compatibility: GNU Emacs 20.x
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Commentary: 
;; 
;;    Some key bindings.
;;
;;  New user options defined here:
;;
;;    `sub-exit-with-confirmation', `sub-kill-buffer-and-its-windows',
;;    `sub-pp-evals', `sub-query-replace-w-options',
;;    `sub-remove-window'.
;;
;;  Other variables defined here:
;;
;;    `comparison-map'.
;;
;;
;;  ***** NOTE: The following user option (variable) defined in
;;              `foldout.el' has been REDEFINED HERE:
;;
;;  `foldout-mouse-modifiers'.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Change log:
;; 
;; RCS $Log: setup-keys.el,v $
;; RCS Revision 1.6  2001/01/09 22:16:56  dadams
;; RCS Adapted file header for Emacs Lisp Archive.
;; RCS
;; RCS Revision 1.5  2001/01/03 17:45:29  dadams
;; RCS *** empty log message ***
;; RCS
;; RCS Revision 1.4  2001/01/03 01:10:22  dadams
;; RCS *** empty log message ***
;; RCS
;; RCS Revision 1.3  2000/12/07 19:53:20  dadams
;; RCS Added require of shrink-fit.el.
;; RCS
;; RCS Revision 1.2  2000/11/28 20:34:24  dadams
;; RCS Optional require's via 3rd arg=t now.
;; RCS
;; RCS Revision 1.1  2000/09/14 17:23:57  dadams
;; RCS Initial revision
;; RCS
; Revision 1.6  1999/10/25  08:36:15  dadams
; Moved to setup-frames.el: Rename minibuffer frame to show show/hide.
;
; Revision 1.5  1999/10/05  14:46:57  dadams
; Added show-hide key binding reminder to name of minibuffer frame.
;
; Revision 1.4  1999/09/03  09:53:06  dadams
; Added: sub-pp-evals. Use it to replace eval-* with pp-eval-*.
;
; Revision 1.3  1999/09/02  08:30:32  dadams
; 1. Added binding for show-hide.
; 2. Added vars: sub-delete/iconify-window, sub-query-replace-w-options,
;    sub-kill-buffer-and-its-windows, sub-exit-with-confirmation. Use to
;    protect substitute-key-definition's.
;
; Revision 1.2  1999/04/13  14:01:54  dadams
; *** empty log message ***
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Code:

(eval-when-compile (require 'cl)) ;; when, unless
(require 'frame-cmds nil t) ;; (no error if not found):
                            ;; iconify-everything, iconify/map-frame,
                            ;; mouse-iconify/map-frame, mouse-remove-window,
                            ;; mouse-show-hide-from-minibuffer, 
mouse-tear-off-window,
                            ;; remove-window, show-*Help*-buffer, show-hide,
(require 'simple+ nil t) ;; (no error if not found): comment-region
(require 'diff+ nil t) ;; (no error if not found): diff
(require 'highlight nil t) ;; (no error if not found): highlight
(require 'misc-cmds nil t) ;; (no error if not found): exit-with-confirmation,
                           ;; goto-previous-mark, goto-previous-global-mark,
                           ;; kill-buffer-and-its-windows, region-to-buffer,
                           ;; region-to-file, yank-secondary
(require 'unaccent nil t) ;; (no error if not found): unaccent-region, 
unaccent-word
(require 'replace+ nil t) ;; (no error if not found): query-replace-w-options
(require 'pp+ nil t) ;; (no error if not found): pp-eval-expression
(require 'buff-menu+ nil t) ;; (no error if not found): buffer-menu
(require 'help+ nil t) ;; (no error if not found): help-on-click/key
(require 'files+ nil t) ;; (no error if not found): 
switch-to-buffer-other-window
(require 'shrink-fit nil t) ;; (no error if not found): shrink-frame-to-fit

(autoload 'compare-windows "compare-w"
  "Compare text in current window with text in next window." t)
(autoload 'ediff-buffers "ediff"
  "Run Ediff on a pair of buffers, BUFFER-A and BUFFER-B." t)
(autoload 'ediff-files "ediff"
  "Run Ediff on a pair of files, FILE-A and FILE-B." t)
(autoload 'kill-rectangle "rect"
  "Delete rectangle with corners at point & mark; save as last killed." t)
(autoload 'fill-individual-paragraphs "fill"
  "Fill paragraphs of uniform indentation within the region." t)
(autoload 'ispell-complete-word "ispell4"
  "Complete word using letters at point to word beginning using `look'." t)
(autoload 'forward-whitespace "thingatpt" nil t)
(autoload 'forward-symbol "thingatpt" nil t)
(autoload 'dired-jump-other-window "dired-x"
  "Jump to dired buffer corresponding to current buffer, in new window." t)


(provide 'setup-keys)

;;;;;;;;;;;;;;;;;;;;;;;;

;; Redefinitions of some standard mouse bindings:
;; SGI does not pass all ALT-mouse stuff thru to Emacs, so use C-M-mouse:
(global-set-key [C-M-mouse-1] 'mouse-start-secondary)
(global-set-key [C-M-drag-mouse-1] 'mouse-set-secondary)
(global-set-key [C-M-down-mouse-1] 'mouse-drag-secondary)
(global-set-key [C-M-mouse-3] 'mouse-secondary-save-then-kill)
(global-set-key [C-M-mouse-2] 'mouse-yank-secondary)

(when (fboundp 'yank-secondary)         ; Defined in `misc-cmds.el'.
  (global-set-key "\C-\M-y" 'yank-secondary))
;; Because M-C is being used for secondary.
(defvar foldout-mouse-modifiers '(meta shift) ; Defined in `foldout.el'.
  "*List of modifier keys to apply to foldout's mouse events.")

(when (fboundp 'iconify/map-frame)      ; All of these are defined in 
`frame-cmds.el'.
  (global-set-key "\C-z" 'iconify/map-frame) ; 
Replaces`iconify-or-deiconify-frame'.
  (define-key ctl-x-map [\C-z] 'iconify-everything)
  (global-set-key [mode-line C-mouse-1] 'mouse-tear-off-window)
  (define-key ctl-x-map [?\C-_] 'shrink-frame-to-fit)
  (global-set-key "\M-\C-z" 'show-hide)
  (global-set-key [C-down-mouse-1] 'mouse-show-hide-from-minibuffer)

  ;; These [nil] bindings are no doubt a HACK, based on an undocumented handy 
"feature".
  ;; (This works in Emacs 19.34.6, but it doesn't work in Emacs 20.6.)
  ;; In Windows, at least, such a key sequence [nil...] occurs if you click in 
the 
  ;; lower right corner, between the scroll bar and the mode-line.
  (global-set-key [nil down-mouse-1] 'shrink-frame-to-fit)
  (global-set-key [nil mouse-1] 'ignore)
  (global-set-key [nil C-down-mouse-1] 'show-hide)
  (global-set-key [nil C-mouse-1] 'ignore)
  (global-set-key [nil S-down-mouse-1] 'iconify-everything)
  (global-set-key [nil S-mouse-1] 'ignore)

  ;; [mode-line mouse-3] as deletion (Emacs std) is too hazardous.  Iconify 
instead.
  (global-set-key [mode-line mouse-3] 'mouse-iconify/map-frame)
  (global-set-key [mode-line C-mouse-3] 'mouse-remove-window)) ; Defined in 
`frame-cmds.el'

;;; Put *Help* buffer in `help-minor-mode'.
;;(save-excursion (set-buffer (get-buffer-create "*Help*")) (help-minor-mode 1))

;;;; Help mouse-menu.
;;(when (fboundp 'help-mouse-menu)        ; In `help-minor.el'.
;;  (unless (lookup-key (current-global-map) [C-M-S-down-mouse-1])
;;    (global-set-key [C-M-S-down-mouse-1] 'help-mouse-menu)
;;    (global-set-key [C-M-S-mouse-1] 'ignore))
;;  (unless (lookup-key (current-global-map) [C-M-S-down-mouse-2])
;;    (global-set-key [C-M-S-down-mouse-2] 'help-mouse-menu)
;;    (global-set-key [C-M-S-mouse-2] 'ignore))
;;  (unless (lookup-key (current-global-map) [C-M-S-down-mouse-3])
;;    (global-set-key [C-M-S-down-mouse-3] 'help-mouse-menu)
;;    (global-set-key [C-M-S-mouse-3] 'ignore)))

;; Comparisons: windows, buffers, files.
(global-set-key [?\C-\M-=] 'compare-windows) ; Defined in `compare-w.el'.
(defvar comparison-map (lookup-key global-map [?\C-=]))
(unless (keymapp comparison-map)
  (setq comparison-map (make-sparse-keymap))
  (define-key global-map [?\C-=] comparison-map)
  (define-key comparison-map "b" 'ediff-buffers) ; Defined in `ediff.el'.
  (define-key comparison-map "e" 'ediff-files) ; Defined in `ediff.el'.
  (define-key comparison-map "f" 'ediff-files) ; Defined in `ediff.el'.
  (define-key comparison-map "d" 'diff) ; Defined in `diff+.el'.
  (define-key comparison-map "w" 'compare-windows) ; Defined in `compare-w.el'.
  )

;; Completions (non-minibuffer).
;(global-set-key "\M-\r" 'complete)      ; Defined in `completion.el':
;(global-set-key [?\C-\r] 'complete)
;(define-key function-key-map [C-return] [?\C-\r])

(define-key text-mode-map "\M-j" 'fill-individual-paragraphs) ; Defined in 
`fill.el'.
(global-set-key "\M-$" 'ispell-complete-word)
(global-set-key "\M-_" 'forward-whitespace) ; Defined in `thingatpt.el'
(global-set-key "\M-s" 'forward-symbol) ; Defined in `thingatpt.el'

(when (fboundp 'unaccent-word)          ; Defined in `unaccent.el'.
  (global-set-key "\M-\"" 'unaccent-word) ; Defined in `unaccent.el'.
  (define-key ctl-x-map [\"] 'unaccent-region)) ; Defined in `unaccent.el'.

(define-key ctl-x-map [?\C-\;] 'comment-region) ; Defined in `simple+.el'.
(define-key ctl-x-map "w" 'region-to-file) ; Defined in `misc-cmds.el'.
(define-key ctl-x-map "\ex" 'repeat-matching-complex-command) ; `chistory.el'.
(define-key ctl-x-map "c" 'font-lock-mode)
(define-key ctl-x-map "\C-y" 'highlight) ; Defined in `highlight.el'.
(define-key ctl-x-map "\C-j" 'dired-jump) ; Defined in `dired-x.el'.
(define-key ctl-x-4-map "\C-j" 'dired-jump-other-window) ; In `dired-x.el'.
(when (fboundp 'show-*Help*-buffer)
  (define-key ctl-x-5-map "h" 'show-*Help*-buffer)) ; Defined in 
`frame-cmds.el'.

;; [tab] function key (distinguished here from C-i).
(global-set-key [C-tab] 'goto-previous-mark) ; Defined in `misc-cmds.el'.
(global-set-key [C-M-tab] 'goto-previous-global-mark) ; In `misc-cmds.el'.

;; [f1] function key.
(when (fboundp 'help-on-click/key)
  (global-set-key [f1] 'help-on-click/key)) ; Standard binding is `help-command'
(global-set-key [C-f1] 'kill-buffer)
(global-set-key [M-f1] 'switch-to-buffer-other-window) ; New version in 
`files+.el'.
(global-set-key [S-f1] 'revert-buffer)
(global-set-key [C-S-f1] 'region-to-buffer) ; Defined in `misc-cmds.el'.
(global-set-key [M-S-f1] 'insert-buffer) ; Defined in `simple.el'.
(global-set-key [C-M-f1] 'font-lock-fontify-buffer) ; Defined in `font-lock.el'
(global-set-key [C-M-S-f1] 'rename-buffer)

;; [insert] key.  [C-insert] is `kill-ring-save'.  [S-insert] is `yank'.
(global-set-key [M-insert] 'yank-pop) ; Defined in `simple.el'.
(global-set-key [C-S-insert] 'insert-buffer) ; Defined in `simple.el'.
(global-set-key [M-S-insert] 'yank-rectangle)
(global-set-key [C-M-insert] 'lisp-complete-symbol)
(global-set-key [C-M-S-insert] 'insert-file)

;; [delete] key.
(global-set-key [delete] 'kill-line)    ; Defined in `simple.el'.
(global-set-key [C-delete] 'kill-paragraph) ; Defined in `paragraphs.el'.
(global-set-key [M-delete] 'kill-ring-save) ; Defined in `simple.el'.
; Emacs standard: [S-delete] is `kill-region'.
(global-set-key [C-S-delete] 'append-next-kill) ; Defined in `simple.el'.
(global-set-key [M-S-delete] 'kill-rectangle) ; Defined in `rect.el'.
(global-set-key [C-M-delete] 'kill-sexp) ; Defined in `lisp.el'.
(global-set-key [C-M-S-delete] 'append-to-register) ; Defined in `register.el'.

;; [backspace] key.
(global-set-key [C-backspace] 'backward-kill-paragraph) ; In `paragraphs.el'.
(global-set-key [C-S-backspace] 'region-to-file) ; Defined in `misc-cmds.el'.
(global-set-key [M-S-backspace] 'clear-rectangle) ; Defined in `rect.el'.
; Emacs standard [C-M-backspace] is `backward-kill-sexp' (defined in `lisp.el')
(global-set-key [C-M-S-backspace] 'copy-to-register) ; In `register.el'.

;; `iso-transl.el' is needed to use an ISO prefix key (e.g. `C-x 8'. [pause]).
(require 'iso-transl)                   ; Defines `key-translation-map'.
;;;@@@Emacs20 ;; This lets users do `[pause] C-h]' for help on ISO chars.
;;;@@@Emacs20 (autoload 'help-iso-prefix "help+"
;;;@@@Emacs20   "Show commands bound to ISO (pseudo-)prefix key sequences." t)

;; [pause] / [break] key:
;; NOTE: On Windows, [C-pause] is considered to be [C-cancel].

;; Make [pause] key be a synonym for `C-x 8'. (Use [pause] as a compose key.)
(define-key key-translation-map [pause] ; See `iso-transl.el'.
  (lookup-key key-translation-map "\C-x8"))
;; Make [pause] key be a synonym for `C-x 8' for isearch too.
;; This lets you search for accented chars using [pause]. 
(define-key isearch-mode-map [pause] nil)
;;;@@@Emacs20 ;; [pause] C-h and C-x 8 C-h  :=  Help for [pause] and C-x 8 
prefixes:
;;;@@@Emacs20 (global-set-key (vector 'pause help-char) 'help-iso-prefix) ; In 
`help.el'.
;;;@@@Emacs20 (define-key ctl-x-map "8\C-h" 'help-iso-prefix) ; Defined in 
`help.el'.

;; These *declp* commands are defined in `misc-cmds.el'.
;(global-set-key [C-print] 'declp-buffer) ; Print buffer. (defsubst)
;(global-set-key [M-print] 'pr-declp-buffer) ; Print buffer via `pr'.
;(global-set-key [C-M-print] 'declp-buffer-w-switches) ; User `declp' switches.
;(global-set-key [S-print] 'transpose-paragraphs) ; Defined in `paragraphs.el'
;(global-set-key [C-S-print] 'declp-region) ; Print region. (defsubst)
;(global-set-key [M-S-print] 'pr-declp-region) ; Print region via `pr'.
;(global-set-key [C-M-S-print] 'declp-region-w-switches) ; `declp' + switches.

;; [home], [end], [prior], and [next] keys.  These are used, unmodified, by
;; `s-region-move', which is defined in `s-region+.el'. The following commands,
;; except `forward-page' & `backward-page', are also defined in `s-region+.el'.
;(global-set-key [C-prior] 'backward-page) ; Defined in `page.el'.
;(global-set-key [C-previous] 'backward-page)
;(global-set-key [C-next] 'forward-page) ; Defined in `page.el'.
;(global-set-key [next] 'scroll-up-windowful) ; Defined in `s-region+.el'.
;(global-set-key [previous] 'scroll-down-windowful) ; Defined in `s-region+.el'.
;(global-set-key [prior] 'scroll-down-windowful)
;(global-set-key [M-next] 'scroll-other-window-up-windowful) ; In `s-region+.el'
;(global-set-key [M-previous] 'scroll-other-window-down-windowful)
;(global-set-key [M-prior] 'scroll-other-window-down-windowful) ; `s-region+.el'
;(global-set-key [home] 'goto-point-min) ; (defsubst) Defined in `s-region+.el'.
;(global-set-key [end] 'goto-point-max) ; (defsubst) Defined in `s-region+.el'.
;(global-set-key [M-home] 'bob-other-window) ; (defsubst) In `s-region+.el'.
;(global-set-key [M-end] 'eob-other-window) ; (defsubst) In `s-region+.el'.
;(s-region-bind (list [prior] [C-prior] [M-prior]))

;; [up], [down], [left], [right] keys.
(global-set-key [S-down] '(lambda () (interactive)(scroll-up 1)))
(global-set-key [S-up] '(lambda () (interactive)(scroll-down 1)))
(global-set-key [M-up] (lookup-key esc-map "p")) ; Probably not defined.
(global-set-key [M-down] (lookup-key esc-map "n")) ; Probably not defined.
(global-set-key [C-M-up] 'backward-list) ; Defined in `lisp.el'.
(global-set-key [C-M-down] 'forward-list) ; Defined in `lisp.el'.
;;(global-set-key [M-left] (lookup-key esc-map "b")) ; Predefined.
;;(global-set-key [M-right] (lookup-key esc-map "f")) ; Predefined.
(global-set-key [C-M-left] 'backward-sexp)
(global-set-key [C-M-right] 'forward-sexp)


;;;-----------REPLACEMENT BINDINGS------------------------------------

;;;###autoload
(defvar sub-remove-window t
  "*Non-nil => `substitute-key-definition' of `remove-window' for that
of `delete-window', everywhere.")

;;;###autoload
(defvar sub-query-replace-w-options t
  "*Non-nil => `substitute-key-definition' of `query-replace-w-options'
for that of `query-replace', everywhere.")

;;;###autoload
(defvar sub-kill-buffer-and-its-windows t
  "*Non-nil => `substitute-key-definition' of `kill-buffer-and-its-windows'
for that of `kill-buffer', everywhere.")

;;;###autoload
(defvar sub-exit-with-confirmation t
  "*Non-nil => `substitute-key-definition' of `exit-with-confirmation'
for that of `save-buffers-kill-emacs', everywhere.")

;;;###autoload
(defvar sub-pp-evals t
  "*Non-nil => `substitute-key-definition' of `pp-eval-*' commands
for the plain `eval-*' commands, everywhere. Thus, `pp-eval-expression'
replaces `eval-expression' and `pp-eval-last-sexp' replaces
\`eval-last-sexp'")

;; Do this *after* load `menu-bar+.el', since that sets original bindings.
(when (and sub-remove-window (fboundp 'remove-window))
  (substitute-key-definition 'delete-window ; Defined in `frame-cmds.el'.
                             'remove-window global-map))
(when (and sub-query-replace-w-options (fboundp 'query-replace-w-options))
  (substitute-key-definition 'query-replace ; Defined in `replace+.el'.
                             'query-replace-w-options global-map))
(when (and sub-kill-buffer-and-its-windows
           (fboundp 'kill-buffer-and-its-windows))
  (substitute-key-definition 'kill-buffer ; Defined in `misc-cmds.el'.
                             'kill-buffer-and-its-windows global-map))
(when (and sub-exit-with-confirmation (fboundp 'exit-with-confirmation))
  (substitute-key-definition 'save-buffers-kill-emacs ; In `misc-cmds.el'.
                             'exit-with-confirmation global-map)) ; (defsubst)
(when sub-pp-evals
  (substitute-key-definition 'eval-last-sexp
                             'pp-eval-last-sexp global-map) ; In `pp.el'.
  (substitute-key-definition 'eval-expression
                             'pp-eval-expression global-map)) ; In `pp+.el'.
(when (fboundp 'buffer-menu)
  (substitute-key-definition 'list-buffers ; Redefined in `buff-menu+.el'.
                             'buffer-menu global-map))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; `setup-keys.el' ends here



reply via email to

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