comparison lisp/simple.el @ 83387:0181341f0aca

Fix Delete key on X by adapting normal-erase-is-backspace-mode for multi-tty. (Reported by Dan Waber and Dan Nicolaescu.) * lisp/frame.el (terminal-parameter-p): New function. (terminal-parameter): Use it. * lisp/simple.el (normal-erase-is-backspace): Add 'maybe option, set it as default. (normal-erase-is-backspace-mode): Rewrite for multiple display support. (normal-erase-is-backspace-setup-frame): New function. * lisp/frame.el (make-frame): Call it. * lisp/startup.el (command-line): Call it. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-427
author Karoly Lorentey <lorentey@elte.hu>
date Sun, 23 Oct 2005 22:11:22 +0000
parents db4e74787e6f
children 732c5740ca8f
comparison
equal deleted inserted replaced
83386:db4e74787e6f 83387:0181341f0aca
5235 (clone-indirect-buffer nil t norecord))) 5235 (clone-indirect-buffer nil t norecord)))
5236 5236
5237 5237
5238 ;;; Handling of Backspace and Delete keys. 5238 ;;; Handling of Backspace and Delete keys.
5239 5239
5240 (defcustom normal-erase-is-backspace 5240 (defcustom normal-erase-is-backspace 'maybe
5241 (and (not noninteractive) 5241 "Set the default behaviour of the Delete and Backspace keys.
5242 (or (memq system-type '(ms-dos windows-nt)) 5242
5243 (eq initial-window-system 'mac) 5243 If set to t, Delete key deletes forward and Backspace key deletes
5244 (and (memq initial-window-system '(x)) 5244 backward.
5245 (fboundp 'x-backspace-delete-keys-p) 5245
5246 (x-backspace-delete-keys-p)) 5246 If set to nil, both Delete and Backspace keys delete backward.
5247 ;; If the terminal Emacs is running on has erase char 5247
5248 ;; set to ^H, use the Backspace key for deleting 5248 If set to 'maybe (which is the default), Emacs automatically
5249 ;; backward and, and the Delete key for deleting forward. 5249 selects a behaviour. On window systems, the behaviour depends on
5250 (and (null initial-window-system) 5250 the keyboard used. If the keyboard has both a Backspace key and
5251 (eq tty-erase-char ?\^H)))) 5251 a Delete key, and both are mapped to their usual meanings, the
5252 "If non-nil, Delete key deletes forward and Backspace key deletes backward. 5252 option's default value is set to t, so that Backspace can be used
5253 5253 to delete backward, and Delete can be used to delete forward.
5254 On window systems, the default value of this option is chosen 5254
5255 according to the keyboard used. If the keyboard has both a Backspace 5255 If not running under a window system, customizing this option
5256 key and a Delete key, and both are mapped to their usual meanings, the 5256 accomplishes a similar effect by mapping C-h, which is usually
5257 option's default value is set to t, so that Backspace can be used to 5257 generated by the Backspace key, to DEL, and by mapping DEL to C-d
5258 delete backward, and Delete can be used to delete forward. 5258 via `keyboard-translate'. The former functionality of C-h is
5259 5259 available on the F1 key. You should probably not use this
5260 If not running under a window system, customizing this option accomplishes 5260 setting if you don't have both Backspace, Delete and F1 keys.
5261 a similar effect by mapping C-h, which is usually generated by the
5262 Backspace key, to DEL, and by mapping DEL to C-d via
5263 `keyboard-translate'. The former functionality of C-h is available on
5264 the F1 key. You should probably not use this setting if you don't
5265 have both Backspace, Delete and F1 keys.
5266 5261
5267 Setting this variable with setq doesn't take effect. Programmatically, 5262 Setting this variable with setq doesn't take effect. Programmatically,
5268 call `normal-erase-is-backspace-mode' (which see) instead." 5263 call `normal-erase-is-backspace-mode' (which see) instead."
5269 :type 'boolean 5264 :type '(choice (const :tag "Off" nil)
5265 (const :tag "Maybe" maybe)
5266 (other :tag "On" t))
5270 :group 'editing-basics 5267 :group 'editing-basics
5271 :version "21.1" 5268 :version "21.1"
5272 :set (lambda (symbol value) 5269 :set (lambda (symbol value)
5273 ;; The fboundp is because of a problem with :set when 5270 ;; The fboundp is because of a problem with :set when
5274 ;; dumping Emacs. It doesn't really matter. 5271 ;; dumping Emacs. It doesn't really matter.
5275 (if (fboundp 'normal-erase-is-backspace-mode) 5272 (if (fboundp 'normal-erase-is-backspace-mode)
5276 (normal-erase-is-backspace-mode (or value 0)) 5273 (normal-erase-is-backspace-mode (or value 0))
5277 (set-default symbol value)))) 5274 (set-default symbol value))))
5278 5275
5276 (defun normal-erase-is-backspace-setup-frame (&optional frame)
5277 "Set up `normal-erase-is-backspace-mode' on FRAME, if necessary."
5278 (unless frame (setq frame (selected-frame)))
5279 (with-selected-frame frame
5280 (unless (terminal-parameter-p nil 'normal-erase-is-backspace)
5281 (if (cond ((terminal-parameter-p nil 'normal-erase-is-backspace)
5282 (terminal-parameter nil 'normal-erase-is-backspace))
5283 ((eq normal-erase-is-backspace 'maybe)
5284 (and (not noninteractive)
5285 (or (memq system-type '(ms-dos windows-nt))
5286 (eq window-system 'mac)
5287 (and (memq window-system '(x))
5288 (fboundp 'x-backspace-delete-keys-p)
5289 (x-backspace-delete-keys-p))
5290 ;; If the terminal Emacs is running on has erase char
5291 ;; set to ^H, use the Backspace key for deleting
5292 ;; backward and, and the Delete key for deleting forward.
5293 (and (null window-system)
5294 (eq tty-erase-char ?\^H)))))
5295 (t
5296 normal-erase-is-backspace))
5297 (normal-erase-is-backspace-mode 1)
5298 (normal-erase-is-backspace-mode 0)))))
5279 5299
5280 (defun normal-erase-is-backspace-mode (&optional arg) 5300 (defun normal-erase-is-backspace-mode (&optional arg)
5281 "Toggle the Erase and Delete mode of the Backspace and Delete keys. 5301 "Toggle the Erase and Delete mode of the Backspace and Delete keys.
5282 5302
5283 With numeric arg, turn the mode on if and only if ARG is positive. 5303 With numeric arg, turn the mode on if and only if ARG is positive.
5284 5304
5285 On window systems, when this mode is on, Delete is mapped to C-d and 5305 On window systems, when this mode is on, Delete is mapped to C-d
5286 Backspace is mapped to DEL; when this mode is off, both Delete and 5306 and Backspace is mapped to DEL; when this mode is off, both
5287 Backspace are mapped to DEL. (The remapping goes via 5307 Delete and Backspace are mapped to DEL. (The remapping goes via
5288 `function-key-map', so binding Delete or Backspace in the global or 5308 `local-function-key-map', so binding Delete or Backspace in the
5289 local keymap will override that.) 5309 global or local keymap will override that.)
5290 5310
5291 In addition, on window systems, the bindings of C-Delete, M-Delete, 5311 In addition, on window systems, the bindings of C-Delete, M-Delete,
5292 C-M-Delete, C-Backspace, M-Backspace, and C-M-Backspace are changed in 5312 C-M-Delete, C-Backspace, M-Backspace, and C-M-Backspace are changed in
5293 the global keymap in accordance with the functionality of Delete and 5313 the global keymap in accordance with the functionality of Delete and
5294 Backspace. For example, if Delete is remapped to C-d, which deletes 5314 Backspace. For example, if Delete is remapped to C-d, which deletes
5306 probably not turn on this mode on a text-only terminal if you don't 5326 probably not turn on this mode on a text-only terminal if you don't
5307 have both Backspace, Delete and F1 keys. 5327 have both Backspace, Delete and F1 keys.
5308 5328
5309 See also `normal-erase-is-backspace'." 5329 See also `normal-erase-is-backspace'."
5310 (interactive "P") 5330 (interactive "P")
5311 (setq normal-erase-is-backspace 5331 (set-terminal-parameter
5312 (if arg 5332 nil 'normal-erase-is-backspace
5313 (> (prefix-numeric-value arg) 0) 5333 (if arg
5314 (not normal-erase-is-backspace))) 5334 (> (prefix-numeric-value arg) 0)
5335 (not (terminal-parameter nil 'normal-erase-is-backspace))))
5315 5336
5316 (cond ((or (memq window-system '(x w32 mac pc)) 5337 (cond ((or (memq window-system '(x w32 mac pc))
5317 (memq system-type '(ms-dos windows-nt))) 5338 (memq system-type '(ms-dos windows-nt)))
5318 (let ((bindings 5339 (let* ((lfkm (terminal-local-value 'local-function-key-map nil))
5319 `(([C-delete] [C-backspace]) 5340 (bindings
5320 ([M-delete] [M-backspace]) 5341 `(([C-delete] [C-backspace])
5321 ([C-M-delete] [C-M-backspace]) 5342 ([M-delete] [M-backspace])
5322 (,esc-map 5343 ([C-M-delete] [C-M-backspace])
5323 [C-delete] [C-backspace]))) 5344 (,esc-map
5324 (old-state (lookup-key function-key-map [delete]))) 5345 [C-delete] [C-backspace])))
5325 5346 (old-state (lookup-key lfkm [delete])))
5326 (if normal-erase-is-backspace 5347
5348 (if (terminal-parameter nil 'normal-erase-is-backspace)
5327 (progn 5349 (progn
5328 ;; XXX Perhaps this mode should be terminal-local, not global -- lorentey 5350 (define-key lfkm [delete] [?\C-d])
5329 (define-key function-key-map [delete] [?\C-d]) 5351 (define-key lfkm [kp-delete] [?\C-d])
5330 (define-key function-key-map [kp-delete] [?\C-d]) 5352 (define-key lfkm [backspace] [?\C-?]))
5331 (define-key function-key-map [backspace] [?\C-?])) 5353 (define-key lfkm [delete] [?\C-?])
5332 (define-key function-key-map [delete] [?\C-?]) 5354 (define-key lfkm [kp-delete] [?\C-?])
5333 (define-key function-key-map [kp-delete] [?\C-?]) 5355 (define-key lfkm [backspace] [?\C-?]))
5334 (define-key function-key-map [backspace] [?\C-?]))
5335 5356
5336 ;; Maybe swap bindings of C-delete and C-backspace, etc. 5357 ;; Maybe swap bindings of C-delete and C-backspace, etc.
5337 (unless (equal old-state (lookup-key function-key-map [delete])) 5358 (unless (equal old-state (lookup-key lfkm [delete]))
5338 (dolist (binding bindings) 5359 (dolist (binding bindings)
5339 (let ((map global-map)) 5360 (let ((map global-map))
5340 (when (keymapp (car binding)) 5361 (when (keymapp (car binding))
5341 (setq map (car binding) binding (cdr binding))) 5362 (setq map (car binding) binding (cdr binding)))
5342 (let* ((key1 (nth 0 binding)) 5363 (let* ((key1 (nth 0 binding))
5344 (binding1 (lookup-key map key1)) 5365 (binding1 (lookup-key map key1))
5345 (binding2 (lookup-key map key2))) 5366 (binding2 (lookup-key map key2)))
5346 (define-key map key1 binding2) 5367 (define-key map key1 binding2)
5347 (define-key map key2 binding1))))))) 5368 (define-key map key2 binding1)))))))
5348 (t 5369 (t
5349 (if normal-erase-is-backspace 5370 (if (terminal-parameter nil 'normal-erase-is-backspace)
5350 (progn 5371 (progn
5372 ;; XXX This should be terminal-local -- lorentey
5351 (keyboard-translate ?\C-h ?\C-?) 5373 (keyboard-translate ?\C-h ?\C-?)
5352 (keyboard-translate ?\C-? ?\C-d)) 5374 (keyboard-translate ?\C-? ?\C-d))
5353 (keyboard-translate ?\C-h ?\C-h) 5375 (keyboard-translate ?\C-h ?\C-h)
5354 (keyboard-translate ?\C-? ?\C-?)))) 5376 (keyboard-translate ?\C-? ?\C-?))))
5355 5377