I have a bunch of keywords:
which each can be shortened down to one letter:
Further, these keywords are case-insensitive, so the following are added to the mix:
Given a list of the basic keywords
("set" "write" "quit"), how can I create a regular expression that will match them as I describe?
I've approached it by providing a list to
regexp-opt, but the case-insensitivity list is proving hard to write. Here is what I have so far:
(defun mumps--command-variants (command &optional stack) "Returns the possible abbreviations of COMMAND. For example, input of \"set\" would yield the list \(\"s\" \"se\" \"set\")" (let ((case-insensitive-command-list (mumps--case-insensitize command)))) (if (= 1 (length command)) (cons command stack) (mumps--command-variants (substring command 0 (1- (length command))) (cons command stack))))
Note on use-case
This is going to be used to create font-lock keywords for a major mode for editing MUMPS code. MUMPS is an... interesting language: command names are case-insensitive (and can be abbreviated like this), but everything else in the language is case-sensitive (and cannot be abbreviated). Furthermore, there is no syntactical difference between a expression which uses a command and that which uses a function (a subroutine of commands), but one is case-insensitive/abbreviated and the other is not.