PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/editor/Minibuffer.cs

http://github.com/toshok/shelisp
C# | 128 lines | 118 code | 10 blank | 0 comment | 2 complexity | 1fddcd6a56bf2f41b04a6a34004ee7a5 MD5 | raw file
Possible License(s): GPL-3.0
  1. using System;
  2. using System.IO;
  3. using Shelisp;
  4. namespace Shemacs.Editor {
  5. public class Minibuffer {
  6. [LispBuiltin (DocString = @"Return common substring of all completions of STRING in COLLECTION.
  7. Test each possible completion specified by COLLECTION
  8. to see if it begins with STRING. The possible completions may be
  9. strings or symbols. Symbols are converted to strings before testing,
  10. see `symbol-name'.
  11. All that match STRING are compared together; the longest initial sequence
  12. common to all these matches is the return value.
  13. If there is no match at all, the return value is nil.
  14. For a unique match which is exact, the return value is t.
  15. If COLLECTION is an alist, the keys (cars of elements) are the
  16. possible completions. If an element is not a cons cell, then the
  17. element itself is the possible completion.
  18. If COLLECTION is a hash-table, all the keys that are strings or symbols
  19. are the possible completions.
  20. If COLLECTION is an obarray, the names of all symbols in the obarray
  21. are the possible completions.
  22. COLLECTION can also be a function to do the completion itself.
  23. It receives three arguments: the values STRING, PREDICATE and nil.
  24. Whatever it returns becomes the value of `try-completion'.
  25. If optional third argument PREDICATE is non-nil,
  26. it is used to test each possible match.
  27. The match is a candidate only if PREDICATE returns non-nil.
  28. The argument given to PREDICATE is the alist element
  29. or the symbol from the obarray. If COLLECTION is a hash-table,
  30. predicate is called with two arguments: the key and the value.
  31. Additionally to this predicate, `completion-regexp-list'
  32. is used to further constrain the set of candidates.")]
  33. public static Shelisp.Object Ftry_completion (L l, Shelisp.Object str, Shelisp.Object collection, [LispOptional] Shelisp.Object predicate)
  34. {
  35. Console.WriteLine ("try-completion (str = {0}, collection = {1}) not implemented", str, collection); return str;
  36. }
  37. [LispBuiltin]
  38. public static Shelisp.Object Fcompleting_read (L l, Shelisp.Object prompt, Shelisp.Object collection, [LispOptional] Shelisp.Object predicate, Shelisp.Object require_match,
  39. Shelisp.Object initial_input, Shelisp.Object hist, Shelisp.Object def, Shelisp.Object inherit_input_method)
  40. {
  41. Console.Write (prompt.ToString("princ"));
  42. return (Shelisp.String)Console.ReadLine ();
  43. }
  44. [LispBuiltin]
  45. public static Shelisp.Object Fall_completions (L l, Shelisp.Object str, Shelisp.Object collection, Shelisp.Object predicate, Shelisp.Object hide_spaces)
  46. {
  47. Console.WriteLine ("all-completions (str = {0}) not implemented", str);
  48. return L.Qnil;
  49. }
  50. [LispBuiltin (DocString = @"Text properties that are added to minibuffer prompts.
  51. These are in addition to the basic `field' property, and stickiness
  52. properties.")]
  53. public static Shelisp.Object Vminibuffer_prompt_properties = new List (L.intern ("read-only"), new List (L.Qt, L.Qnil));
  54. [LispBuiltin (DocString = @"Read a string from the minibuffer, prompting with string PROMPT.
  55. The optional second arg INITIAL-CONTENTS is an obsolete alternative to
  56. DEFAULT-VALUE. It normally should be nil in new code, except when
  57. HIST is a cons. It is discussed in more detail below.
  58. Third arg KEYMAP is a keymap to use whilst reading;
  59. if omitted or nil, the default is `minibuffer-local-map'.
  60. If fourth arg READ is non-nil, interpret the result as a Lisp object
  61. and return that object:
  62. in other words, do `(car (read-from-string INPUT-STRING))'
  63. Fifth arg HIST, if non-nil, specifies a history list and optionally
  64. the initial position in the list. It can be a symbol, which is the
  65. history list variable to use, or a cons cell (HISTVAR . HISTPOS).
  66. In that case, HISTVAR is the history list variable to use, and
  67. HISTPOS is the initial position for use by the minibuffer history
  68. commands. For consistency, you should also specify that element of
  69. the history as the value of INITIAL-CONTENTS. Positions are counted
  70. starting from 1 at the beginning of the list.
  71. Sixth arg DEFAULT-VALUE, if non-nil, should be a string, which is used
  72. as the default to `read' if READ is non-nil and the user enters
  73. empty input. But if READ is nil, this function does _not_ return
  74. DEFAULT-VALUE for empty input! Instead, it returns the empty string.
  75. Whatever the value of READ, DEFAULT-VALUE is made available via the
  76. minibuffer history commands. DEFAULT-VALUE can also be a list of
  77. strings, in which case all the strings are available in the history,
  78. and the first string is the default to `read' if READ is non-nil.
  79. Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
  80. the current input method and the setting of `enable-multibyte-characters'.
  81. If the variable `minibuffer-allow-text-properties' is non-nil,
  82. then the string which is returned includes whatever text properties
  83. were present in the minibuffer. Otherwise the value has no text properties.
  84. The remainder of this documentation string describes the
  85. INITIAL-CONTENTS argument in more detail. It is only relevant when
  86. studying existing code, or when HIST is a cons. If non-nil,
  87. INITIAL-CONTENTS is a string to be inserted into the minibuffer before
  88. reading input. Normally, point is put at the end of that string.
  89. However, if INITIAL-CONTENTS is \(STRING . POSITION), the initial
  90. input is STRING, but point is placed at _one-indexed_ position
  91. POSITION in the minibuffer. Any integer value less than or equal to
  92. one puts point at the beginning of the string. *Note* that this
  93. behavior differs from the way such arguments are used in `completing-read'
  94. and some related functions, which use zero-indexing for POSITION.")]
  95. public static Shelisp.Object Fread_from_minibuffer (L l, Shelisp.Object prompt,
  96. [LispOptional] Shelisp.Object initial_contents, Shelisp.Object keymap, Shelisp.Object read, Shelisp.Object hist, Shelisp.Object default_value, Shelisp.Object inherit_input_method)
  97. {
  98. Console.Write (prompt.ToString("princ"));
  99. var input = Console.ReadLine ();
  100. if (L.NILP (read))
  101. return (Shelisp.String)input;
  102. else {
  103. return Reader.ReadFromString (input);
  104. }
  105. }
  106. }
  107. }