Commit Graph

1412 Commits

Author SHA1 Message Date
Qi Xiao
504e507ef8 pkg/md/fmt.go: Escape forbidden characters inside autolinks. 2022-11-05 11:50:08 +00:00
Qi Xiao
a0d308d23c pkg/md/fmt.go: Stop incrementing ordered list item's number at 9 9's. 2022-11-05 00:39:24 +00:00
Qi Xiao
8c0e2e17da pkg/md/fmt.go: Introduce an intermediate output for inline formatting.
This is to prepare for adding reflow support.
2022-11-04 22:28:55 +00:00
Qi Xiao
25c3e37e9b pkg/md: Relax FmtCodec's requirements for the input.
- Handle newlines in emphasis and strong emphasis.

- Handle code blocks and HTML blocks with missing closer.

- Strip trailing blank lines when parsing HTML blocks.

- Fix corner cases in info strings of code fences.
2022-11-04 19:05:17 +00:00
Qi Xiao
a4589bcdf0 pkg/md: Refine formatting style.
- Try to avoid escaping & and < when they are not problematic.

- Escape non-breaking space.

- Format lists as loose lists.

- Only indent inline raw HTML when it can actually be parsed as a
  paragraph-interrupting HTML block.
2022-11-04 18:09:17 +00:00
Qi Xiao
b901b49f12 cmd/elvmdfmt: Split Markdown formatting into own command, supporting -w and -d.
Also change the behavior of the rendering command (elvmd) to still output HTML
when given -trace.
2022-11-04 16:37:47 +00:00
Qi Xiao
ef5acc9c4b pkg/md/fmt.go: Avoid trailing spaces in blank lines. 2022-11-04 14:23:38 +00:00
Qi Xiao
9c1c0c923e pkg/md: Fix more bugs found by fuzzing. 2022-11-04 12:51:54 +00:00
Qi Xiao
d30cf3e9ab pkg/md/fmt_test.go: Remove test for the idempotency of FmtCodec.
It is redundant for the existing check that the HTML output of formatted
markdown remains the same.
2022-11-03 23:53:26 +00:00
Qi Xiao
6fabd0f6a8 pkg/md: Fix numerous corner cases found by fuzzing. 2022-11-03 23:46:13 +00:00
Qi Xiao
f278185904 pkg/md/fmt.go: Fix how new stanzas are introduced. 2022-11-03 03:13:06 +00:00
Qi Xiao
4996be7221 pkg/md: Fix nil pointer access in processEmphasis. 2022-11-03 02:34:39 +00:00
Qi Xiao
57cde859b6 pkg/md: Don't support nested emphasis or strong emphasis in FmtCodec.
Correctly formatting nested emphasis or strong emphasis is just too hard.

Also don't support consecutive emphasis or strong emphasis.
2022-11-03 02:27:25 +00:00
Qi Xiao
6cb2a1f50d cmd/elvmd: Consolidate mdfmt and mdtrace into elvmd.
Also export pkg/md.HTMLCodec, and make it the default in elvmd.
2022-11-02 13:22:44 +00:00
Qi Xiao
1320f16b5f pkg/md: Fix more bugs discovered by fuzzing.
- When parsing starting markers, consider the rest of the line to be in a new
  paragraph after one marker is parsed.

- FmtCodec: Escape info string in fenced code blocks.

- FmtCodec: Use "_" as emphasis marker also after end of emphasis or strong emphasis.
2022-11-02 13:13:33 +00:00
Qi Xiao
d1f09b47de pkg/md: Fix and simplify insertion of hard line breaks. 2022-11-02 11:55:29 +00:00
Qi Xiao
96e4f75e43 Add a new "mdtrace" for debugging the md package with the trace codec. 2022-11-02 02:20:28 +00:00
Qi Xiao
b61dc859ad pkg/md: Add fuzz tests, and fix some bugs found by them.
- Avoid reformatting "- - *" as "- - -"; the former is a 3-level list with no
  content, the latter is a thematic break.

- Escape "~~~" at the start of line.

- When handling escapes inside ATX headings, use "i == 0" as a condition for
  start of line, since we are actually not at the literal start of line after
  writing the heading starter.

- Fix the definition of Unicode punctuations to be consistent with the spec.
2022-11-02 02:03:19 +00:00
Qi Xiao
dddc5d273e pkg/md: Handle code and HTML blocks with missing closers. 2022-11-02 01:05:56 +00:00
Qi Xiao
9b901b2508 pkg/md: Test that FmtCodec is idempotent. 2022-11-01 23:59:47 +00:00
Qi Xiao
eb4a84540a pkg/md/fmt.go: Improve escaping.
- Only escape "!" when followed by a link.

- Only escape "#" when it is either at the start of line in a paragraph and
  introduce an ATX heading, or is at the end of the line in an ATX heading and
  can be parsed as the optional ATX heading closer.

- Escape "-" and "+" if and only if they can introduce a bullet list.

- Escape "." and ")" if and only if they come after a number and can introduce
  an ordered list.

- Escape ">" when it can introduce blockquote.

- Escape spaces and tabs at start and end of line.
2022-11-01 23:46:47 +00:00
Qi Xiao
947bcc0eb6 pkg/md: Separate block and inline ops. 2022-11-01 20:43:51 +00:00
Qi Xiao
289f3dfb46 pkg/md/fmt_test.go: Enable most supplemental test cases. 2022-10-30 23:33:00 +00:00
Qi Xiao
e16ab05078 pkg/md/fmt.go: Format link destination and title. 2022-10-30 23:28:14 +00:00
Qi Xiao
db56c9b318 pkg/md: Alternate between * and _ for consecutive OpEmphasisStart's. 2022-10-30 18:41:09 +00:00
Qi Xiao
f3397a746f pkg/md: Alternate list marker's punctuation when it follows immediately after another. 2022-10-30 18:02:45 +00:00
Qi Xiao
806286cfa1 pkg/md: Comment and simplify the fields of FmtCodec. 2022-10-30 16:53:15 +00:00
Qi Xiao
614cdca1f9 Merge branch 'master' into builtin-elvdoc 2022-10-28 19:22:08 +01:00
Qi Xiao
a08ab691df pkg/md: Fix newlines around HTML blocks in FmtCodec.
Also:

- Show a trace of Op's when a test case fails.

- Don't loosify lists when comparing the HTML output of original and formatted.
2022-10-28 19:20:39 +01:00
Qi Xiao
89063ab095 Manually cherry-pick codespell changes from #1613. 2022-10-23 23:57:01 +01:00
Kurtis Rader
eb1770f2b9 Add a benchmark command
Resolves #1586
2022-10-23 23:37:07 +01:00
Qi Xiao
a0be886c87 pkg/md: Clarify package godoc. 2022-10-23 23:34:44 +01:00
Qi Xiao
f584434735 Add md.FmtCodec and a mdfmt command.
A lot of tests are skipped for now.
2022-10-15 12:21:11 +01:00
Qi Xiao
ffc05aba8d pkg/md: Generate String method for OpType.
Also standardize the name of the file generated by stringer as "zstring.go" and
ignore all existing ones in .codecov.yml.
2022-10-15 11:39:27 +01:00
Qi Xiao
9d75552d0b pkg/md: Split test utilities from md_test.go into testutils_test.go. 2022-10-15 11:34:48 +01:00
Qi Xiao
b846cfa60b pkg/md/md_test.go: Add comment on the escape* functions. 2022-10-07 13:00:23 +01:00
Qi Xiao
871c0833b9 Add LICENSE for CommonMark spec.
Already clarify the wording of the license description in general.
2022-10-07 10:46:30 +01:00
Qi Xiao
4c27a9e551 Merge branch 'master' into builtin-elvdoc 2022-10-07 10:36:17 +01:00
Qi Xiao
dad7c6f035 README: Clarify license. 2022-10-05 01:29:52 +01:00
Qi Xiao
c928d16527 pkg/md: Add supplemental tests to cover all reachable code.
Also make the handling of raw HTML in image alt consistent with cmark.
2022-10-05 01:12:29 +01:00
Qi Xiao
6a7b189a51 pkg/md/md_test: Reorder supplemental tests to match section order in spec. 2022-10-05 00:23:18 +01:00
Qi Xiao
ab9054971d pkg/md: Only support a minimum set of HTML entities.
This avoids a dependency on the html package, which has a huge entity table.

The pkg/md package is not used by Elvish now, but its impact on the binary size
can be measured by exposing md.Render as a builtin function.

- With the dependency on the html package, Elvish's binary size would increase by
  206KiB.

- Without the dependency, the binary size would only increase by 125KiB.
2022-10-05 00:12:36 +01:00
Qi Xiao
a1a9193f93 pkg/md: Update package doc. 2022-10-04 23:28:08 +01:00
Qi Xiao
ca67bbd038 pkg/md: Remove source from HTML block condition 6.
This matches this post-0.30 change of the spec: 053924aa51
2022-10-04 23:21:30 +01:00
Qi Xiao
b7d72cc089 pkg/md: Rearrange code and add comments. 2022-10-04 23:20:54 +01:00
Qi Xiao
165f5ba261 pkg/md: Use a Python-like dedent function to make test cases more readable. 2022-10-04 21:55:52 +01:00
Qi Xiao
e545d88442 pkg/md: Simplify blank lines closing blockquotes. 2022-10-04 21:35:47 +01:00
Qi Xiao
30b2ec5540 pkg/md: Refactor and add comments.
- Use a Codec interface to specify output format.

  This gives more control over how output is built, and will make it possible to
  build a terminal renderer.

- Refactor block tree logic into its own type.

- Handle the opening and closing of list containers in one place.

- Use lookahead to implement the rule allowing only one blank line to start a
  list item.

- Remove handling for non-\n line endings.

  This is required by the spec, but there is no test for it. It was also not
  handled consistently before; if there is a need, it is easier to just
  normalize the line ending at the very beginning rather than handling it
  everywhere.
2022-10-04 21:09:22 +01:00
Qi Xiao
4e8ac3c12b pkg/md: Handle entities in links and autolinks correctly.
Entities in link destination and title need to be handled as part of the parsing
procedure, instead of after it. The spec doesn't have test cases for this, so
added new supplemental test cases.

Entity support in autolinks also don't have test cases in the spec, so add a
supplemental test case too.
2022-10-03 17:18:06 +01:00
Qi Xiao
3bef3fd55c pkg/md: Rearrange code and add some links to spec. 2022-10-03 06:17:19 +01:00
Qi Xiao
afaf977217 pkg/md: Split inline syntax into a separate file. 2022-10-03 05:58:32 +01:00
Qi Xiao
0b81091545 pkg/md: Support indented code blocks. 2022-10-03 05:52:41 +01:00
Qi Xiao
e091971598 pkg/md: Don't skip with regexp match.
Indented code blocks and link reference definitions are used a lot in other
sections, and they used to be skipped by matching the markdown with regexp
patterns. However, this has some false positives, so list the individual example
IDs instead.
2022-10-03 05:07:37 +01:00
Qi Xiao
3ff0e4bcd9 pkg/eval: Check whether variable name is empty when parsing lvalue.
This fixes #1560.
2022-10-03 04:34:05 +01:00
Kurtis Rader
e896ac3c0e
Improve some compilation errors (#1617)
Quote variable names appearing in some compilation errors to improve
the clarity of those errors.
2022-10-03 04:22:46 +01:00
Qi Xiao
ce87939ade pkg/md: Accept at most 3 leading spaces in thematic break and ATX heading. 2022-10-03 04:07:58 +01:00
Qi Xiao
dee9199878 pkg/md: Handle backslashes and entities in code fence info string. 2022-10-03 03:34:26 +01:00
Qi Xiao
bfb0a380c2 pkg/md: Support starting a list item with a blank line. 2022-10-03 03:19:52 +01:00
Qi Xiao
a2a7126064 pkg/md: Support HTML blocks. 2022-10-03 02:51:07 +01:00
Qi Xiao
e9e7827592 pkg/md: Support fenced code blocks. 2022-10-02 23:27:32 +01:00
Qi Xiao
5d9521cb57 pkg/md: Add helpers for building HTML tags in tests. 2022-10-02 22:20:12 +01:00
Qi Xiao
d0cb8f9860 pkg/md: Enable the test in the Precedence section. 2022-10-02 21:13:27 +01:00
Qi Xiao
9425865de9 pkg/md: Only allow ordered lists starting with 1 to interrupt paragraphs. 2022-10-02 21:11:32 +01:00
Qi Xiao
1e3043bb4f pkg/md: Refine list support, and enable more tests. 2022-10-02 21:02:33 +01:00
Qi Xiao
cc8a7b2207 pkg/md: Preliminary list support. 2022-10-02 20:44:30 +01:00
Qi Xiao
8d85b89a05 pkg/md: Support thematic breaks, ATX headings and blockquotes.
Also rearrange fields of OutputSyntax to match the order they appear in the
CommonMark spec.
2022-10-02 01:25:05 +01:00
Qi Xiao
befab9b5f0 pkg/md: Parse multiple paragraphs. 2022-10-02 01:25:05 +01:00
Qi Xiao
9f6a55ce30 pkg/md: Render blocks, not just inline text.
This now handles the entire input as one paragraph block.

Also test the package via its exported API.
2022-10-02 01:24:55 +01:00
Qi Xiao
1eb45fab22 pkg/md/md_test.go: List unsupported sections instead of supported sections. 2022-09-26 01:16:58 +01:00
Qi Xiao
383a7f2696 pkg/md: Support HTML entities. 2022-09-26 01:07:51 +01:00
Qi Xiao
5bf0cf7d6c pkg/md: New package for Markdown renderer. 2022-09-26 00:08:15 +01:00
Qi Xiao
241f15de42 Clean up tests introduced in #1604 slightly. 2022-09-11 15:58:58 +01:00
kas
93c9f86555 Add support for completing invocations of local executables 2022-09-11 15:54:13 +01:00
rok
f4f96b47b8 vi append command binding 2022-09-11 15:36:53 +01:00
Qi Xiao
27e2df9394 Remove edit:-dump-buf.
This used to be used for taking ttyshots but is now obsolete.
2022-09-11 15:33:59 +01:00
Kurtis Rader
2f21892e0c
Documentation fixups (#1584)
I noticed these functions didn't have a "usage" while working on a `help` command.

Co-authored-by: Qi Xiao <xiaq@users.noreply.github.com>
2022-09-11 15:28:32 +01:00
Qi Xiao
f8f0f3e889 Fixup for #1588 2022-08-29 12:29:24 +01:00
Kurtis Rader
eed6a995dd
Support comparing booleans (#1588)
Fixes #1585
2022-08-29 12:25:54 +01:00
Kurtis Rader
a549dba0ba Add missing "usage" text for three commands
I noticed this when testing my `help` command and noticed that
`help builtin:` produced three lines of "usage" text that did not
include a function or variable name.
2022-08-29 12:10:31 +01:00
Qi Xiao
8cb125c911 Improve documentation for %. 2022-08-29 12:09:43 +01:00
Kurtis Rader
c6e10f12a2 Some minor documentation fixes
Mostly elimination of duplicated words but also a few other fixes such
as the output of commands such as `%`.
2022-08-29 12:04:59 +01:00
Qi Xiao
595f00ae51 pkg/glob: Add a comment on symlink resolution. 2022-08-29 11:51:26 +01:00
Qi Xiao
21e951427f pkg/edit/highlight: Highlight the catch keyword. 2022-08-29 11:18:57 +01:00
Qi Xiao
629cc9c85e Fix elvdoc for compact. 2022-08-29 11:08:19 +01:00
Kurtis Rader
03539c3e70 Remove redundant math: var usage text
Resolves #1580
2022-08-28 23:04:00 +01:00
Qi Xiao
acf470f104 New "compact" command.
This fixes #1453.
2022-08-28 22:58:37 +01:00
Qi Xiao
181c4dde55 pkg/eval: Create builtin_fn_stream_test.go.
Tests for functions defined in builtin_fn_stream.go are moved there.
2022-08-28 22:08:00 +01:00
Qi Xiao
9ce24d616e Fixup for #1567.
- Don't skip glob_test on Windows.

- Document the change as a breaking change.
2022-08-28 21:55:56 +01:00
Kurtis Rader
a72224d7f0 Fix glob expansion that includes broken symlinks
Glob expansion should use os.Lstat rather than os.Stat so that broken
symlinks don't stop glob expansion. It's not the place of glob expansion
to decide if a particular path is good.

The symlink test cases and logic were borrowed from
pkg/mods/path/path_test.go.

Fixes #1240
2022-08-28 21:46:39 +01:00
Qi Xiao
7c75510407 pkg/mods/runtime: Make $elvish-path $nil if os.Executable returns an error. 2022-08-13 11:42:16 +01:00
Qi Xiao
c2a5533a61
Merge branch 'master' into issue-1423-expose-elvish-path 2022-08-13 11:35:41 +01:00
Qi Xiao
afc3c140d9 Improve doc on conditionally importing a module.
- Expand the example in edit:add-var, and give it a h3.

- Add a link from the language reference to the section in edit:add-var.

This fixes #1116.
2022-08-13 11:26:13 +01:00
Qi Xiao
da07880430 Tweak docs introduced in #1563. 2022-08-13 10:59:22 +01:00
Kurtis Rader
1638311854 Implement path:join, separator, and list-separator
Resolves #1562
2022-08-13 10:55:20 +01:00
Qi Xiao
3dcfa88c8d Remove go1.18 build tags as 1.18 is required. 2022-08-08 12:29:33 +01:00
Qi Xiao
1b8ccdbdbc pkg/eval: Deduplicate range implementations with generics. 2022-08-08 12:28:47 +01:00
Kurtis Rader
3239c38764 Add runtime:elvish-path
Resolves #1423
2022-08-07 19:32:34 -07:00
Qi Xiao
551e246d96 webiste/cmd/macros: Strip leading $ from anchor targets of @cf.
Also add previously missing $'s in @cf arguments. This doesn't matter for the
anchor target, but matters for the link text.
2022-08-08 00:09:17 +01:00
Qi Xiao
9794eecd68 Add new runtime module.
This module provides $runtime:{lib-dirs rc-path effective-rc-path}. It will
likely grow in future.

This fixes #1385.
2022-08-08 00:09:02 +01:00
Qi Xiao
2e788c846d Run gofmt.
https://tip.golang.org/doc/go1.19#go-doc
2022-08-07 22:30:11 +01:00
Qi Xiao
bd569f8132 pkg/eval: Add a note about the use of echo in after-chdir's example. 2022-08-07 22:25:47 +01:00
Qi Xiao
46008d111b Add -randseed to set RNG seed.
This is used in ttyshots to get deterministic outputs.

This command is prefixed with - since I'd like to eventually move rand and
randint into their own module, so this command will be moved too.
2022-08-07 11:32:52 +01:00
Qi Xiao
41fc578002 Merge branch 'ttyshot' 2022-08-04 23:41:11 +01:00
Qi Xiao
40275b97f1 Rewrite elvdoc for styled and styled-segment.
Also document the behavior of ignoring SGR state in the 0.19.0 release notes.
2022-07-24 14:44:16 +01:00
Qi Xiao
42c6c3b1aa pkg/ui: Make styled text context-insensitive, and remove the "default" color.
Styled text is not supposed to "inherit" the current SGR styling context when
written to the terminal. This has always been the intention, but not correctly
implemented. This commit fixes that for both styled segments and styled texts.
Tests are amended to account for the difference in the output.

With context insensitivity correctly implemented, there is now no need for a
"default" color. It is functionally equivalent to a lack of color.

The parsing of SGR still needs to be aware of the codes 39 (default foreground)
and 49 (default background), but these codes are now translated into FgDefault
and BgDefault, which resets the foreground and background color fields.
2022-07-24 14:31:02 +01:00
Qi Xiao
b47f8e0dc2 pkg/shell: Add a short delay in signal handling test. 2022-06-23 22:03:12 +01:00
Qi Xiao
fed2113a66 pkg/shell: Add build tag to shell_unix_test.go. 2022-06-23 21:54:57 +01:00
Qi Xiao
4fb96d515c pkg/shell: Test signal handling. 2022-06-23 21:48:12 +01:00
Qi Xiao
fbf0bfc13b pkg/sys: Double init size of stack trace buf.
4KB is likely insufficient.
2022-06-23 21:48:12 +01:00
Qi Xiao
6810de7384 pkg/shell: Clean up signal handling goroutine.
This is not necessary for actual uses of Elvish, but can leave a lot of
goroutines running in tests.
2022-06-23 21:48:12 +01:00
Qi Xiao
ed97664695 pkg/eval: Test the exit command by faking os.Exit. 2022-06-23 20:25:01 +01:00
Qi Xiao
7855bc0fd7 pkg/cli/modes: Improve nav mode test coverage. 2022-06-21 23:27:36 +01:00
Qi Xiao
75c230f5eb pkg/cli/lscolors: Increase test coverage. 2022-06-20 23:24:11 +01:00
Qi Xiao
98ee4aebdd pkg/cli/histutil: Ignore coverage of testDB. 2022-06-20 23:06:07 +01:00
Qi Xiao
e0292dd298 Get coverage on IsStructMap methods with a hack. 2022-06-20 22:08:19 +01:00
Qi Xiao
400ada5c86 pkg/logutil: Add tests. 2022-06-20 22:03:58 +01:00
Qi Xiao
af4ca7d75b pkg/buildinfo: Improve test coverage. 2022-06-20 21:13:34 +01:00
Qi Xiao
4afbb71c07 Move pkg/testutil/must.go to a new pkg/must. 2022-06-20 20:29:14 +01:00
Qi Xiao
d2c005df45 pkg/eval: Test import of module with invalid UTF-8. 2022-06-20 00:14:25 +01:00
Qi Xiao
786b679509 pkg/eval: Cover more tilde expansion errors. 2022-06-20 00:08:33 +01:00
Qi Xiao
6723b9a226 Use consistent pattern for mutating variables in tests.
- Use testutil.Set.

- Only export such variables to tests.
2022-06-19 23:56:18 +01:00
Qi Xiao
94e43cd2fd pkg/eval: Add tests for errors in tilde expansion. 2022-06-19 23:34:36 +01:00
Qi Xiao
35e236aee7 pkg/shell: Add more scripting tests. 2022-06-19 22:45:24 +01:00
Qi Xiao
6a1e7b3996 pkg/shell: Add more daemon-related tests.
Also:

- Remove duplicate code for closing daemon client.

- Avoid using (*testing.T).TempDir - it uses test name in the path, which can
  exceed the limit of the address when calling bind(2):
  https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_un.h.html#tag_13_6
7_04
2022-06-19 21:45:36 +01:00
Qi Xiao
e06bf69a74 pkg/shell: Add tests for DB path. 2022-06-19 20:29:50 +01:00
Qi Xiao
78d914b24b pkg/shell: Run TestInteract_ConnectsToDaemon on Windows too.
This test now succeeds on Windows too, now that the daemon also uses Unix
sockets on Windows.
2022-06-19 19:08:11 +01:00
Qi Xiao
a3cc6a44f0 pkg/daemon: Fix a comment. 2022-06-19 19:06:24 +01:00
Qi Xiao
3d0196b7d3 pkg/shell: De-export makeEvaler and incSHLVL.
Change the test cases against InvSHLVL to test the behavior of the Program
instead.
2022-06-19 15:43:23 +01:00
Qi Xiao
6cb2fd3855 Treat $XDG_DATA_DIRS as semicolon-delimited on Windows. 2022-06-19 14:41:25 +01:00
Qi Xiao
2506b578b9 pkg/shell: Test against XDG environment variables.
Also fix how $XDG_DATA_DIRS is handled.
2022-06-19 14:30:37 +01:00
Kurtis Rader
4b4726b9a6 Make ttyshots scripted and reproducible
The main benefits of this change are:

1) It uses a hermetic "home" directory with a known command and location
   history. Which means it no longer depends on the interactive history
   and directory layout of the person creating the ttyshot. Which also
   means it no longer leaks the private history of anyone creating a
   ttyshot. This produces reproducible results when updating ttyshots.

2) The user no longer has to augment the ttyshot by manually adding the
   output of the commands to the generated HTML file. A process that is
   error prone. The output of the commands that generate the ttyshot is
   now captured and automatically included in the resulting HTML.

3) It makes it trivial to recreate every ttyshot. Simply execute these
   commands:

   ```
   make ttyshot
   for f [website/ttyshot/**.spec] { put $f; ./ttyshot $f }
   ```

4) It makes it easy to introduce new "ttyshot" images by creating a
   shell session "spec" file. This makes it easy to replace the existing
   "```elvish-transcript...```" examples with ttyshots in order to
   ensure a consistent representation and visual consistency with the
   transcripts that are currently generated as ttyshots.

The downside of this change is the introduction of a dependency on the
Tmux application. But that seems reasonable since Tmux is a mature
application available on Linux, macOS, BSD, and probably every other
UNIX like OS we care about. Note that generating the Elvish
documentation already depends on similar apps such as Pandoc.

Related #1459
2022-06-19 10:51:29 +01:00
Qi Xiao
75ee261fcb pkg/eval: Remove access methods for exported fields.
The exported fields are intended to be mutated directly.
2022-06-18 19:01:59 +01:00
Qi Xiao
d48b6f1843 pkg/eval/vals: Replace MakeListFromStrings with a generic MakeListSlice. 2022-06-17 16:50:38 +01:00
Qi Xiao
01756ef57a pkg/daemon: Ignore error when closing connections on shutdown.
The logs are not useful anyway since the reason is invariably that the client
has already closed the connection.

Moreover, timing in the shutdown sequence causes fluctuation in test coverage;
removing this log eliminates the fluctuation.
2022-06-14 21:01:50 +01:00
Qi Xiao
4a6405eeb4 pkg/edit/complete: Improve analysis of variable definitions.
- Remove the sigil from the variable name.

- Recognize function parameters too.
2022-06-14 20:50:57 +01:00
Qi Xiao
e0ee14ad68 Support completing variables defined in the code being completed. 2022-06-13 23:00:06 +01:00
Qi Xiao
534be70bfb Simplify implementation of variable completion.
There is no need to enumerate namespaces separately, since namespaces are also
variables. The only exceptions are "e:" and "E:", which are handled as special
cases now.
2022-06-13 22:50:44 +01:00
Qi Xiao
6564b14898 Fix crash when completing code with unexpected rune.
This fixes #1530.
2022-06-12 21:39:51 +01:00
Qi Xiao
f3ea882bd2 Warn about files in ~/.elvish instead of the directory itself. 2022-06-12 14:21:57 +01:00
Qi Xiao
ae9e6d1565 Fixup for #1531.
- Fix the handling of actual occurrences of U+FFFD.

- Fix an existing bug of QuoteVariableName("$\n").
2022-06-11 21:26:32 +01:00
Kurtis Rader
d0f6858b95 Correctly encode strings with invalid UTF-8
In addition to fixing the encoding bugs standardize on \xNN notation for
bytes rather than \uNNNN; e.g., \x00 rather than \u0000.

Also, update the documentation for double-quoted strings to include the
\e sequence.

Fixes #1528
2022-06-11 20:42:06 +01:00
Qi Xiao
49115dba1d Respect $XDG_* directories on Windows.
This fixes #1481.
2022-06-09 22:48:39 +01:00
Qi Xiao
cb8628bcb6 Print a warning if ~/.elvish exists as a directory.
This addresses #1554.
2022-06-07 23:35:13 +01:00
Qi Xiao
68bce3b4a4 Clarify error message when writing values to port not supporting it.
This fixes #1516.
2022-06-07 20:29:34 +01:00
Qi Xiao
f42c2dda61 Make init value of $f~ actually identical to $nop~.
This fixes #1519.
2022-06-07 20:20:00 +01:00
Qi Xiao
5bf0290741 pkg/cli/term: Support surrogate pairs on Windows.
This fixes #1502.
2022-06-06 23:12:54 +01:00
Qi Xiao
2c30cf9806 Fix staticcheck errors on Windows. 2022-06-05 22:46:24 +01:00
Qi Xiao
f043bd33fb Fixup for #1549. 2022-06-05 22:37:52 +01:00
Kurtis Rader
fa704d6ac6 Implement edit:command-abbr
It turns out that the "small word" abbreviation mechanism I added isn't
really what I, or most users, want. What users really want, at least
most of the time, is the Fish shell abbreviation behavior of expanding
an abbreviation only in the command head position.

Resolves #1472
2022-06-05 22:15:07 +01:00
Qi Xiao
8b0c7fdb36 Fix some lint warnings found on Windows. 2022-06-05 22:01:16 +01:00
Qi Xiao
d4dd11a981 pkg/eval/vars: Deexport EnvVariable, use Unset/IsSet via interface 2022-06-05 21:47:51 +01:00
Qi Xiao
26a66284a9 Fixup for #1551. 2022-06-05 16:01:10 +01:00
Tw
d27610b3e4 Fix undefined temporary environment restoring issue
Close #1536

Signed-off-by: Tw <tw19881113@gmail.com>
2022-06-05 15:41:19 +01:00
Kurtis Rader
ee309bf1c6 Don't dot import pkg/parse
Qualified imports of pkg/parse outnumber unqualified (66 to 1). Improve
consistency, and clarity, by changing the dot (unqualified) imports of
that package symbols to qualified.
2022-06-04 23:39:19 +01:00
Kurtis Rader
345c5c66dd Don't dot import pkg/ui
Qualified imports of pkg/ui outnumber unqualified (82 to 1). Improve
consistency, and clarity, by changing the dot (unqualified) imports of
that package symbols to qualified.
2022-06-04 23:39:19 +01:00
Kurtis Rader
71cd3835bc Don't dot import pkg/tt
Qualified imports of pkg/tt outnumber unqualified (27 to 24). Improve
consistency, and clarity, by changing the dot (unqualified) imports of
that package symbols to qualified.
2022-06-04 23:39:19 +01:00
Kurtis Rader
f681a73a1d Don't dot import pkg/testutil
Qualified imports of pkg/testutil outnumber unqualified (55 to 7). Improve
consistency, and clarity, by changing the dot (unqualified) imports of
that package symbols to qualified.
2022-06-04 23:39:19 +01:00
Qi Xiao
3a4e7ce1fe pkg/lsp: Populate completionProvider capability.
Needed for conforming clients to start requesting autocompletion.
2022-06-03 20:30:46 +01:00
Kurtis Rader
14321f9e82 Make parse.Source naming more consistent
Fixes #1545
2022-05-29 17:36:29 +01:00
Kurtis Rader
7bae8f2df7 Correctly handle [..=-1] list indexing
Fixes #1518
2022-05-22 20:38:16 +01:00
Qi Xiao
a57275564b Document relationship between *-env commands and E: namespace. 2022-05-22 20:13:17 +01:00
Qi Xiao
aa6d5a6257 Re-enable staticcheck, and fix issues it found. 2022-05-22 11:57:38 +01:00
Qi Xiao
dd3950cec0 Use the new testutil.Set in more places. 2022-04-11 21:55:59 +01:00
Qi Xiao
3a3b8f5700 pkg/edit/complete: Change Complete to take an Evaler.
The PureEvaler abstraction made things unnecessarily complex; it's better to
just create a real Evaler for tests is pretty.

The Evaler has a new ReplaceBuiltin method to make it easier to construct the
expected test result.
2022-04-11 21:39:29 +01:00
Qi Xiao
8519085327 clitest: Make failures in TestBuffer and TestNotesBuffer fatal.
If a buffer (or notes buffer) hasn't appeared, it means that the app is not in
some intended state. Subsequent tests are unlikely to be meaningful, and may run
into race conditions.

A lot of existing code already uses TestBuffer to ensure that a certain state is
reached, and making failures fatal also suits this usage better.

This fixes #1507.
2022-04-09 14:40:52 +01:00
Qi Xiao
f8f60953ad Properly deprecate float64.
- Replace its use with "num" in documentation and test code.

- Add a new "inexact-num" for explicitly converting a number to inexact.

This fixes #1513.
2022-04-09 11:45:15 +01:00
Qi Xiao
6ec410753b evaltest: Fix diff output. 2022-04-07 20:46:30 +01:00
Qi Xiao
cfcef9ec51 pkg/buildinfo: Use Go's buildinfo to derive version of development builds.
This allows the build commands in Makefile and tools/buildall.sh to be
simplified.

Official reproducible builds are now handled as a build variant, and the command
in Makefile no longer tries to produce reproducible builds.

Instructions in PACKAGING.md have been completely rewritten.
2022-04-02 18:18:24 +01:00
Qi Xiao
a8c2d165d3 Simplify pkg/edit/complete/node_path.go with generics.
staticcheck@master crashes when checkling code using generics, disable it in CI
for now.
2022-03-20 16:17:19 +00:00
Qi Xiao
51e4d97568 interface{} -> any now that Elvish requires Go 1.18. 2022-03-20 16:17:19 +00:00
Qi Xiao
f7cb556d9b Require Go 1.18.
- Run "go fix" to remove legacy build tags

- Use staticcheck@master until it has a release that supports Go 1.18

- Turn off autocrlf for Windows tasks
2022-03-20 15:28:23 +00:00
Qi Xiao
957c8a7521 evaltest: Check that stderr is empty if PrintsStderrWith is not called.
Among other things, this will check for deprecation warnings. Also fix test code
that uses deprecated features.
2022-03-20 09:50:05 +00:00
Qi Xiao
ab699bae87 Remove use of deprecated features in bundled modules. 2022-03-19 10:09:44 +00:00
Qi Xiao
0fa5ebac68 Prepare for 0.18.0 release.
The development is now considered to be targeting 0.19.0.
2022-03-18 22:11:35 +00:00
Qi Xiao
e2901118a5 Simplify terminal setup functions.
Remove SetupGlobal and Sanitize and replace them with a SetupForEval, which is
similar to Setup, but called before evaluating code and returns a function to
call after evaluating code.
2022-03-18 10:54:01 +00:00
Qi Xiao
e85afa2cbe Fixup for PR #1499.
- Use filepath.Ext instead of path.Ext

- Use cmp.Diff to generate test failure messages

- Misc stylistic changes
2022-03-12 23:22:34 +00:00
Kurtis Rader
603aae077d Improve searching PATH on Windows for completions
This was extracted from https://github.com/elves/elvish/pull/1326. It
augments that change by honoring $E:PATHEXT and some other
minor improvements.  This matches the behavior of the Go stdlib
os/exec.LookPath() function that is used to decide if what has been typed
(in a non-completion context) represents an external command.
2022-03-12 22:49:52 +00:00
Qi Xiao
5f1673c6c4 Use go-cmp to report unexpected test results.
cmp.Diff panics when comparing a struct that has unexported fields and no String
or Equal method, so change some structs to either export all their fields or
have an Equal method.

This fixes #1136.
2022-03-11 22:49:32 +00:00
Qi Xiao
7cf4b94c5f pkg/lsp: Add no-op textDocument/hover. 2022-03-07 14:39:19 +00:00
Qi Xiao
92c7e4b303 pkg/lsp: Support textDocument/completion. 2022-03-07 14:27:26 +00:00
Qi Xiao
effa267007 Add comment for the semantics of SIGTERM on Windows. 2022-03-06 23:48:46 +00:00
moko256
e56fad4817 On Windows, handle SIGTERM and exit immediately when conhost window was closed. 2022-03-06 23:46:25 +00:00
moko256
c8f678d2a5 On Windows, implement sanitize in pkg/cli/term/setup_windows to cleanup console modes that external command changed 2022-03-06 23:33:17 +00:00
Qi Xiao
d3a31ae193 Revamp command-line flag doc.
- Document all flags, and remove doc for removed flags.

- Update in-code flag descriptions to be more consistent with the markdown doc.
2022-03-03 00:41:39 +00:00
Kurtis Rader
24cca36d7b Document all elvish CLI flags
There was a recent question for which the answer was to use the
`-compileonly` flag but the user didn't realize that because there was
no mention on https://elv.sh/ref/command.html. Similarly, other flags,
like `-decpreation-level`, would benefit from more verbiage than shown by
`elvish -help`.
2022-03-01 23:25:22 +00:00
Qi Xiao
e894ae5f82 Improve the syntax of "try".
* Require at least one of "except" or "finally" to be present. This fixes #1424.

* Rename "except" to "catch". The former will be deprecated from 0.18.0. This
  addresses #1497.
2022-03-01 13:57:00 +00:00
Qi Xiao
b8f4cb001d pkg/edit/highlight: Fix highlighting when "except" is followed by a lambda.
This fixes #1358.
2022-03-01 00:57:46 +00:00
Qi Xiao
e58e5a4e56 pkg/edit/complete: Refactor how parse tree is matched.
- Introduce nodePath to store the complete path to the leaf node.

- Introduce a nodesMatcher abstraction to do pattern matching on nodePath.

Parse tree matching previously requires deeply nested if statements to walk
multiple levels of the tree and (optionally) check the property of nodes. These
are replaced by a single "if np.match(...)", with a single level of nesting.
2022-02-27 11:56:58 +00:00
Qi Xiao
6efce297b2 Update completer for assignment.
- Offer variable names as arguments of "set" or "tmp".

- Stop offering "varname = " at the command head position.
2022-02-27 00:02:10 +00:00
Qi Xiao
d7a9d38731 pkg/eval: Remove reference to the now-gone local: scope. 2022-02-20 23:30:47 +00:00
Kurtis Rader
8c9414a0ec No-daemon build don't panic starting location mode
Fixes #1487
2022-02-20 23:27:24 +00:00
Qi Xiao
1bf3ea3c1b Add $unix:rlimits for manipulating resource limits.
This fixes #959.
2022-02-20 23:22:33 +00:00
Qi Xiao
33a04f8dc1 Revamp flag handling in pkg/prog.
Instead of putting all possible flags in prog.Flags, flags are now registered by
the individual subprograms. The 3 flags -sock, -db and -json are shared by
multiple subprograms and still handled by the prog package.

This new design allows separating the support for -cpuprofile into a separate
subprogram, which is no longer included by the default entry point, making the
binary slightly smaller. A new entrypoint "withpprof" is created.

Also include the LSP subprogram in the nodaemon entry point.
2022-02-05 14:52:29 +00:00
Qi Xiao
ffeb3ab963 Make the LSP server part of the Elvish binary.
Also add tests.
2022-02-05 11:34:14 +00:00
moko256
f4bc35dbd0 Use src.elv.sh/pkg/rpc instead of net/rpc. 2022-01-30 22:49:54 +00:00
Qi Xiao
fda62502ad pkg/edit: Slighly refactor the handling of nil Store. 2022-01-16 21:18:55 +00:00
Christian Walter
f5b645cc2d pkg/edit: Don't call AddDir on storedefs if it is not ready
Signed-off-by: Christian Walter <christian.walter@9elements.com>
2022-01-16 21:18:05 +00:00
Qi Xiao
7d22bb1c28 per/persistent: Update benchmarking results.
Also remove disclaimer about API instability since that is now implied by the
0.x version number of the Go module.
2022-01-05 22:44:12 +00:00
Qi Xiao
b2c6e41cb2 Upgrade the script pkg/persistent/add-slowdown. 2022-01-05 22:37:50 +00:00
Qi Xiao
59459793e3 pkg/persistent: Cons -> Conj.
Cons was a misnomer for the operation of adding an element at the end of a
vector. Follow Clojure's naming here and call this operation Conj.
2022-01-05 22:34:55 +00:00
Qi Xiao
8ed351e386 Add a new "defer" command. 2022-01-05 00:12:35 +00:00
Qi Xiao
84b72af4ca Support using styled text in &display to edit:complex-candidate.
This fixes #1011.
2022-01-03 20:30:00 +00:00
Qi Xiao
38d4553833 Update assignment syntax in docs.
- Also remove the section for the legacy assignment syntax.

- Also add a paragraph to "eval" about upvalues.
2022-01-03 19:45:39 +00:00
Qi Xiao
4350ad48b1 Remove highlighting for legacy assignment syntax. 2022-01-03 00:59:48 +00:00
Qi Xiao
003557c22a Remove support for the legacy lambda syntax.
This fixes #664.
2022-01-03 00:47:41 +00:00
Qi Xiao
be1e144b45 Remove support for the "local:", "up:" and ":" special namespaces.
This fixes #1409.
2022-01-03 00:47:41 +00:00
Qi Xiao
3dd3b780b9 Remove legacy assignment syntax.
This fixes #645.
2022-01-03 00:47:41 +00:00
Qi Xiao
4fcffc5671 Remove most uses of the legacy assignment syntax.
The remaining few uses are in some of the tests, which will be removed later.

This addresses #645.
2022-01-03 00:47:41 +00:00
Qi Xiao
653c9f9d0f Remove dir-history, deprecated since 0.17.0. 2022-01-03 00:47:41 +00:00
Qi Xiao
3abf7f5510 Deprecate the legacy temporary assignment syntax from 0.18.0.
This addresses #1114.
2022-01-03 00:47:24 +00:00
Qi Xiao
fb1e807735 Change \xff and \x377 to encode bytes rather than codepoints.
It was an oversight to make them encode codepoints; they were always intended to
be equivalent to their Go counterparts, which encode bytes and can be used to
write arbitrary byte sequences that are not necessarily valid UTF-8 sequences.
2022-01-02 15:44:20 +00:00
Qi Xiao
d9eb0928e3 Bind Alt-Enter to inserting "\n". 2022-01-01 23:52:34 +00:00
Qi Xiao
11de899040 Add fuzz test for (*eval.Evaler).Check. 2022-01-01 23:52:08 +00:00
Qi Xiao
04173ee8ab Actually fix the O(2^n) code path.
With the previous fix, the parsing algorithm could still backtrack without
making progress given slightly more sophisticated input (see added testdata for
an example).

Instead of trying to parse a temporary assignment when it *could* be one, only
parse it when we are sure that it is. This should now truly fix the issue.
2022-01-01 22:52:56 +00:00
Qi Xiao
9cda3f643e parse: Fix a O(2^n) code path when input is "(" repeated n times.
The parsing function for Form first tries to parse a temp assignment, and
backtracks when an assignment cannot be parsed. When the input is "(" repeated n
times, each level of Form parsing will first try to parse the rest of the code
as an assignment and then backtrack, without making any progress. This results
in a call tree with a branching factor of 2, hence the O(2^n) complexity.

The fix is to first try to parse a head instead, and only try to parse it as a
temp assignment if it does contain "=". This fixes this particular pathological
case, although I'm not 100% sure it eliminates all possibilities of O(2^n) time
complexity.

With the introduction of the "tmp" special command, the current syntax for
temporary assignments will be deprecated and eventually go away, which will
eliminate all backtracking in the parser. In the meanwhile, this fix may be good
enough.

This case was discovered with fuzzing support in Go 1.18. Also add the fuzzing
test data.
2022-01-01 22:20:03 +00:00
Qi Xiao
ae91cf7b1c Fix build on Go 1.16. 2021-12-31 21:13:41 +00:00
Qi Xiao
097e32b375 pkg/eval/vals: Add ReprPlain, Repr without pretty-printing.
Also de-export NoPretty now that it is no longer needed.
2021-12-31 21:05:07 +00:00
Qi Xiao
5bf688cf4d New flag module. 2021-12-31 18:03:24 +00:00
Qi Xiao
de3ac3166d Add a new conversion utility vals.ScanMapToGo. 2021-12-31 18:00:36 +00:00
Qi Xiao
e134ef51e3 Handle all-cap abbreviations in strutil.CamelToDashed.
Also remove support for the "name" field tag from eval.scanOptions - it's not
used anywhere and the use case it was intended for is handled by CamelToDashed.
2021-12-31 16:54:32 +00:00
Qi Xiao
e01e5dd2f5 pkg/getopt: Revamp the API and implementation.
- Don't require creating a Getopt object in the API.

- Add a new Parse function, and rename the existing method to Complete.

- Add an Unknown field to Option to indicate unknown options.

- Rewrite the tests.

- Numerous stylistic changes.
2021-12-31 14:36:01 +00:00
Qi Xiao
d9e14da0db Export eval.Closure and (*eval.Frame).Fork. 2021-12-31 14:28:30 +00:00
Qi Xiao
4906c4aa28 Fix doc for the call builtin. 2021-12-31 12:46:47 +00:00
Qi Xiao
a8844a34f8 Check that blocks in control flows don't have arguments or options.
It is now a compile-time error if they do. This fixes #1456.
2021-12-30 13:49:48 +00:00
Qi Xiao
de5f0e0d32 Add new util vals.MakeListFromStrings. 2021-12-30 13:09:18 +00:00
Qi Xiao
c46fd60270 Properly clear the filter when ascending or descending in nav mode.
Also add regression tests for this behavior.
2021-12-30 12:58:34 +00:00
Qi Xiao
7da15f48fb pkg/eval/vals: Add more conversion helpers.
Also update the comment in conversion.go.
2021-12-29 22:32:25 +00:00
Qi Xiao
f7b5df5de5 Add a new "call" command. 2021-12-29 01:16:44 +00:00
Qi Xiao
46774d7078 Use (*Evaler).Chdir for changing directory in navigation mode.
This will run the hooks and update $E:PWD correctly.
2021-12-28 17:52:09 +00:00
Qi Xiao
1910948a86 edit.md: Upgrade syntax. 2021-12-28 17:11:59 +00:00
Qi Xiao
1ec9c95142 Fix the doc for ttyshots.
- Wrap the command in "print" to get byte output.

- Use global-binding to ensure that the key works in all modes.
2021-12-28 13:01:21 +00:00
Qi Xiao
7da4b58f2f Revise doc for the builtin module.
- Revise the introduction section.

- Link to the notes on commands taking value inputs from all such commands.

- Revise the doc on the "all" command.

- Revise references to the builtin module from the language reference.
2021-12-28 12:01:35 +00:00
Qi Xiao
560bd17c17 pkg/eval: Break up builtin_fn_container.go.
- range -> builtin_fn_num.go

- all, one, take, drop, count, order -> new builtin_fn_stream.go

- repeat -> builtin_fn_io.go

- compare -> builtin_fn_pred.go
2021-12-26 12:22:14 +00:00
Christopher Loessl
bd76b46b8e
Doc update (#1457)
* docs(effective-elvish): follow same style as other docs

e.g., https://elv.sh/ref/language.html

* docs(builtin): ref from take to drop

* docs(language): remove mention of :up and :down ns

* docs(fundamentals): update to new lambda format

* docs(tour): update to new lambda syntax

* docs(builtin): update to new lambda syntax

* docs(language): update to new lambda syntax

* docs(unique-semantics): update to new lambda syntax

* docs(tour): fix typo

* Revert "docs(effective-elvish): follow same style as other docs"

This reverts commit db4306a400c61f5f7b6acec7a1e1f39feb9b1ba0.

https://github.com/elves/elvish/pull/1457#discussion_r775102178
2021-12-26 12:02:00 +00:00
Qi Xiao
b1460e4269 Wording tweak for the doc of edit:add-var. 2021-12-24 01:40:26 +00:00
Kurtis Rader
9cf2cfffa6 Cleanups to rc.elv references 2021-12-24 01:40:01 +00:00
Qi Xiao
3bdd7b49e8 Fixup for #1452 2021-12-20 13:31:53 +00:00
Kurtis Rader
91f21858ac More improvements to edit:add-var documentation
The existing `edit:add-var` documentation incorrectly implies the `$init`
value is optional. It also doesn't include any examples that are useful
in practice. This addresses both shortcomings.
2021-12-20 13:13:56 +00:00
Qi Xiao
db0cf05893 Expand the doc of edit:add-var. 2021-12-18 11:58:12 +00:00
Qi Xiao
c71f46642b Update eawk's doc.
* Remove a superfluous line break in the equivalent Elvish code.

* Keep code in transcripts on the same line to be correctly highlited.

* Add another example using digit-only argument names.
2021-12-17 19:53:30 +00:00
Qi Xiao
046e02869d pkg/eval/vals: Document the use of 0 in UnifyNums. 2021-12-17 10:52:44 +00:00
Qi Xiao
7463203bda pkg/mods: Import pkg/mods/unix. 2021-12-17 00:50:53 +00:00
Qi Xiao
71e5bff8da Replace direct reference to persistent types with their aliases in eval/vals. 2021-12-17 00:21:20 +00:00
Qi Xiao
82d92ad467 pkg/eval/vals: De-export the Eq util and move into a _test file. 2021-12-16 23:55:24 +00:00
moko256
c054b0a24d pkg/cli/term: Use ENABLE_WRAP_AT_EOL_OUTPUT on Windows. 2021-12-16 22:20:44 +00:00
Qi Xiao
089752147a Fixup for #1447. 2021-12-13 01:23:14 +00:00
Kurtis Rader
87656c99fa Replace AnyError in tests with a specific error
The `AnyError` placeholder error can cause tests to succeed for errors
other than what was expected. That is, the use of `AnyError` can mask
bugs in a unit test. So replace it with the specific error, or error type,
the test expects to be raised.

This does not remove the anyError structure because it is used in
the TestCase.DoesNotCompile() method. To keep the size of this change
as small as possible I want to defer updating that use to a separate
change. However, remove the public AnyError var so future test writers
don't attempt to use it.
2021-12-13 01:08:24 +00:00
Qi Xiao
973fe39798 Implement the tmp special command.
This addresses #1114.
2021-12-09 22:12:38 +00:00
Qi Xiao
c1adf58b6d Document using "range n | each" to execute something n times.
This addresses #1433.
2021-12-08 00:32:32 +00:00
Qi Xiao
8cbd39f006 Support calling edit:notify with a styled text.
This fixes #1438.
2021-12-08 00:26:17 +00:00