deadpixi / sam

An updated version of the sam text editor.
Other
430 stars 46 forks source link

Proposals for extending the sam command language #96

Open johnwcowan opened 5 years ago

johnwcowan commented 5 years ago

If this issue draws any interest, I will file separate issues for the separate proposals here, and hopefully at some future date provide PRs for them.

Context: For a variety of reasons, I have been using command-line editors all my working life, starting with DEC Teco, then ed, and finally ex. I'd like to switch to sam -d, but I think the command language needs a bit of extension before I can use it as an ex replacement. This issue provides a brief explanation of the commands I think ought to be added.

l (list): Same as p, but outputs a $ before each newline and a ^ after each newline. If dot includes a line fragment at the beginning, it will not begin with ^; if it includes a line fragment at the end, it will not end with $.

L (lines): Same as p, but outputs a line number before each complete line (not including line fragments). This number is up to 7 characters long and right-justified, and followed by a single space. Line fragments begin with 8 spaces instead.

z (window): Extends dot to complete lines. If followed by +, prints the next w - 1 lines; if followed by -, prints the previous w - 1 lines; sets dot in either case. The default is +. If followed by p, l, or L uses that command for printing. The default is p. Sets dot to what was displayed. See the window option below for how to set the value of w.

[ (yank) file and ] file (put): [ replaces dot with the whole contents of file. ] replaces the whole contents of file with dot. As a special case, ] clears the modified flag on file. This is done because typically the file will not correspond to any external file.

N (next): N+, N-, N0 make the next, previous, or first file in the menu the current file. N by itself is the same as N+.

W (writeall): Writes all modified files: same as X/^-/w, but harder to get wrong.

T tag (tag): Reads through all tag files, which are files namd tags in the directories of the tagpath (see below) to find a matching tag. Then loads the file specified by the tag as if by B, and then searches for the search string specified by the tag, setting dot to it. The -T command line option performs this command at startup.

o option (option): Allows dynamic setting of any of the sam (not samterm) options explained below.

Here are the options I'm proposing. They affect the behavior of the command part of sam. Except as noted, all default to false.

autoread [true|false]: If true, then when a file becomes the current file, check if the last modification of the corresponding external file is later than the last modification of the file, do an e on the file.

autowrite [true|false]: If true, then just before a file stops being the current file, write it out with w if the modified flag is set.

backup [true|false]: If true, and a file is being written externally for the first time, rename the external file from foo to foo~ so that the external file will be re-created. Make sure the file permissions are unchanged.

prompt [true|false]: Before reading from stdin, prompt with * (same as ed prompt).

readonly [true|false]: If true, the w command is forbidden unless an external file is specified. This helps protect against overwriting files being examined by accident.

restricted [true|false]: If true, the cd, !, <, >, and | commands are forbidden outright, and the w and f are forbidden if an external file is specified. This prevents other changes to the file system from being made. Executing as rsam sets both readonly and restricted.

tagpath path: Specifies a colon-separated path of directories in which tags files may be found. It is not an error if such files do not exist. Defaults to ..

window integer: Specifies the window size used by the z command. Can be overridden by the -w command line switch. Defaults to 24.

Query 1: Does any of this require modification of the samterm-to-sam protocol? I hope not.

Query 2: Should the options above go into .samrc (in which case samterm needs to parse and ignore them), or into a separate .samdrc file? The former is more convenient, but the latter makes more sense for remote sam operation.