vt-control.el 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ;;; vt-control.el --- Common VTxxx control functions
  2. ;; Copyright (C) 1993-1994, 2001-2012 Free Software Foundation, Inc.
  3. ;; Author: Rob Riepel <riepel@networking.stanford.edu>
  4. ;; Maintainer: Rob Riepel <riepel@networking.stanford.edu>
  5. ;; Keywords: terminals
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; The functions contained in this file send various VT control codes
  19. ;; to the terminal where emacs is running. The following functions are
  20. ;; available.
  21. ;; Function Action
  22. ;; vt-wide set wide screen (132 characters)
  23. ;; vt-narrow set narrow screen (80 characters)
  24. ;; vt-toggle-screen toggle wide/narrow screen
  25. ;; vt-keypad-on set applications keypad on
  26. ;; vt-keypad-off set applications keypad off
  27. ;; vt-numlock toggle applications keypad on/off
  28. ;;; Usage:
  29. ;; To use enable these functions, simply load this file.
  30. ;; Note: vt-control makes no effort to determine how the terminal is
  31. ;; initially set. It assumes the terminal starts with a width
  32. ;; of 80 characters and the applications keypad enabled. Nor
  33. ;; does vt-control try to restore the terminal when emacs is
  34. ;; killed or suspended.
  35. ;;; Code:
  36. ;;; Global variables
  37. (defvar vt-applications-keypad-p t
  38. "If non-nil, keypad is in applications mode.")
  39. (defvar vt-wide-p nil
  40. "If non-nil, the screen is 132 characters wide.")
  41. ;;; Screen width functions.
  42. (defun vt-wide nil
  43. "Set the screen 132 characters wide."
  44. (interactive)
  45. (send-string-to-terminal "\e[?3h")
  46. (set-frame-width (selected-frame) 132)
  47. (setq vt-wide-p t))
  48. (defun vt-narrow nil
  49. "Set the screen 80 characters wide."
  50. (interactive)
  51. (send-string-to-terminal "\e[?3l")
  52. (set-frame-width (selected-frame) 80)
  53. (setq vt-wide-p nil))
  54. (defun vt-toggle-screen nil
  55. "Toggle between 80 and 132 character screen width."
  56. (interactive)
  57. (if vt-wide-p (vt-narrow) (vt-wide)))
  58. ;;; Applications keypad functions.
  59. (defun vt-keypad-on (&optional tell)
  60. "Turn on the VT applications keypad."
  61. (interactive)
  62. (send-string-to-terminal "\e=")
  63. (setq vt-applications-keypad-p t)
  64. (if (or tell (called-interactively-p 'interactive))
  65. (message "Applications keypad enabled.")))
  66. (defun vt-keypad-off (&optional tell)
  67. "Turn off the VT applications keypad."
  68. (interactive "p")
  69. (send-string-to-terminal "\e>")
  70. (setq vt-applications-keypad-p nil)
  71. (if (or tell (called-interactively-p 'interactive))
  72. (message "Applications keypad disabled.")))
  73. (defun vt-numlock nil
  74. "Toggle VT application keypad on and off."
  75. (interactive)
  76. (if vt-applications-keypad-p
  77. (vt-keypad-off (called-interactively-p 'interactive))
  78. (vt-keypad-on (called-interactively-p 'interactive))))
  79. (provide 'vt-control)
  80. ;;; vt-control.el ends here