command-input.sl 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %
  3. % Command-Input.SL - NMODE Command Input Routines
  4. %
  5. % Author: Alan Snyder
  6. % Hewlett-Packard/CRC
  7. % Date: 27 October 1982
  8. %
  9. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  10. (CompileTime (load extended-char fast-int))
  11. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  12. %
  13. % Command Prefix Character Functions:
  14. %
  15. % A command prefix character function must be tagged with the property
  16. % 'COMMAND-PREFIX. It should also define the property 'COMMAND-PREFIX-NAME
  17. % to be a string that will be used to print the command name of commands
  18. % that include a prefix character that is mapped to that function. (The
  19. % function DEFINE-COMMAND-PREFIX is used to set these properties.) The
  20. % function itself should return a command (see dispatch.sl for a description).
  21. %
  22. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  23. (de define-command-prefix (function-name name-string)
  24. (put function-name 'command-prefix T)
  25. (put function-name 'command-prefix-name name-string)
  26. )
  27. (de prefix-name (ch)
  28. % Return the string to be used in printing a command with this prefix char.
  29. (let ((func (dispatch-table-lookup ch)))
  30. (or (and func (get func 'command-prefix-name))
  31. (string-concat (x-char-name ch) " ")
  32. )))
  33. % Here we define some prefix command functions:
  34. (define-command-prefix 'c-x-prefix "C-X ")
  35. (define-command-prefix 'Esc-prefix "Esc-")
  36. (define-command-prefix 'Lisp-prefix "Lisp-")
  37. (define-command-prefix 'm-x-prefix "M-X ")
  38. (de c-x-prefix ()
  39. (nmode-append-separated-prompt "C-X ")
  40. (let ((ch (input-terminal-character)))
  41. (nmode-complete-prompt (x-char-name ch))
  42. (list (x-char C-X) ch)
  43. ))
  44. (de Esc-prefix ()
  45. (nmode-append-separated-prompt "Esc-")
  46. (let ((ch (input-extended-character)))
  47. (nmode-complete-prompt (x-char-name ch))
  48. (list (x-char ESC) ch)
  49. ))
  50. (de Lisp-prefix ()
  51. (nmode-append-separated-prompt "Lisp-")
  52. (let ((ch (input-terminal-character)))
  53. (nmode-complete-prompt (x-char-name ch))
  54. (list (x-char C-!]) ch)
  55. ))
  56. (de m-x-prefix ()
  57. (list (x-char M-X) (prompt-for-extended-command "Extended Command:")))
  58. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  59. %
  60. % Command Input Functions:
  61. %
  62. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  63. (de input-base-character ()
  64. (X-Base (input-terminal-character))
  65. )
  66. (de input-command ()
  67. % Return either a single (extended) character or a list containing a valid
  68. % prefix character plus its argument (character or string).
  69. (let* ((ch (input-extended-character))
  70. (func (dispatch-table-lookup ch))
  71. )
  72. (if (and func (get func 'command-prefix))
  73. (apply func ())
  74. ch
  75. )))