Commit Graph

983 Commits

Author SHA1 Message Date
Qi Xiao
9c9a473826 pkg/shell: Rearrange files and reduce API surface. 2021-07-10 20:15:03 +01:00
Qi Xiao
2d09e1a500 Implement XDG directory support.
Tests will be added in a followup commit before this branch is merged.

This addresses #383.
2021-07-10 02:20:59 +01:00
Qi Xiao
ebf02e3a91 Fix build on Go 1.15. 2021-07-09 01:30:26 +01:00
Qi Xiao
be84cb0a86 Explicitly handle -h as an unsupported flag. 2021-07-09 01:16:19 +01:00
Qi Xiao
671c76be00 Add a lint Makefile target and CI task.
Both run staticcheck and go vet (but not golint).

Also make some small changes necessary to make the codebase lint-free under
staticcheck.
2021-07-08 00:13:38 +01:00
Qi Xiao
d15218f11e Fixup for #1354. 2021-07-07 23:25:01 +01:00
Kurtis Rader
85c499f110 Lint cleanups
This change addresses issues reported by the `staticcheck` tool and a
couple reported by the `golint` tool. It also adds missing issue links
to a couple of entries in the release notes. This change deliberately
does not address these warnings since it is unclear whether the project
owner would prefer to suppress or address them:

    pkg/store/cmd.go:8:2: should not use dot imports (ST1001)
    pkg/store/db_store.go:10:2: should not use dot imports (ST1001)
    pkg/store/dir.go:8:2: should not use dot imports (ST1001)
2021-07-07 23:21:02 +01:00
Qi Xiao
00c7205e81 Fixup for #1348. 2021-07-03 20:34:56 +01:00
Kurtis Rader
3ba0397c34 Add buildinfo and version vars
Introduce `builtin:buildinfo` and `builtin:version` vars. This also
changes the `-buildinfo -json` implementation to use the standard
encoding/json package rather than handcrafting the JSON string.

This also fixes three incorrect spellings of "overridden". Normally I would
do those in a separate change but since there are only three instances,
one of which one was legitimately part of this change, I decided to bundle
the other two.
2021-07-03 20:21:40 +01:00
Kurtis Rader
de9ae18fa8 Fix go vet error about unreachable code 2021-07-03 20:00:59 +01:00
Qi Xiao
d92c4bc08a Refactor shell and daemon initialization code.
In particular, the code for retrieving file paths needed by the runtime is
simplified a lot, and the paths only needed for the storage daemon is cleanly
separated from other paths.
2021-06-28 20:02:38 +01:00
Qi Xiao
fc887b2466 Expand the elvdoc for edit:notify. 2021-06-28 15:10:58 +01:00
Qi Xiao
75a3d5bfb3 Add back edit:notify.
Also correct the doc for return-{line eof}.
2021-06-28 15:09:39 +01:00
Qi Xiao
9981b2a777 Reduce the flakiness of TestPeach with some random jitter.
There was a recent failure of the test that checks peach is
nondeterministic: https://github.com/elves/elvish/runs/2926941131

The failure can be reproduced reliably when setting GOMAXPROCS=1.
However, GitHub Action's Windows runner has two CPU cores, which means
GOMAXPROCS should be 2. Presumably, during that particular one, one of
the cores is occupied by another process, so Go had to run the
goroutines in order on one CPU core.

Go's time.Sleep yields the current goroutine and allow other scheduled
goroutines to run on the same thread. As a result, adding a random
jitter guarantees nondeterminism in execution order, even if only one
CPU core is available to execute threads.

Also run the nondeterminism check in an infinite loop.
2021-06-28 00:46:27 +01:00
Qi Xiao
8c97ed2184 pkg/daemon: Don't depend on net.ErrClosed.
It was added in Go 1.16, but we still support building with Go 1.15.
2021-06-28 00:13:14 +01:00
Qi Xiao
3b390f0792 pkg/daemon: Be slightly less chatty in logs. 2021-06-27 23:57:01 +01:00
Qi Xiao
480bca8f34 Add a missing cleanup in progtest_test.go.
The missing cleanup is leaving some directories unremoved in the system temporary directory.
2021-06-27 23:35:43 +01:00
Qi Xiao
42867d56ba Remove the -bin flag.
Always determine it with os.Executable() instead.
2021-06-27 23:12:09 +01:00
Qi Xiao
7364eff3da Mark internal flags as such in their usage messages. 2021-06-27 22:58:12 +01:00
Qi Xiao
a12e1be189 Implement Hash for *big.Int and *big.Rat. 2021-06-27 17:01:12 +01:00
Qi Xiao
4afab8804b Fixup for #1342. 2021-06-27 16:41:07 +01:00
Kurtis Rader
3da541c719 Other float64 cases that should be generalized
While pondering issue #1340 I looked at the other `case float64:`
blocks. This change generalizes the few places that need it.

Fixes #1340
2021-06-27 16:32:38 +01:00
Kurtis Rader
d303c37987 Test more combinations of Text/Segment+num
This fixes the *Segment.Concat and RConcat methods to handle the new
number types. It also adds more tests of concatenation with the "Text"
and "Segment" types with number types.

Related #1340
2021-06-27 16:32:38 +01:00
Qi Xiao
3d49f02593 Document that "eq" requires values to have the same type to be considered equal.
This fixes #1288.
2021-06-27 01:54:31 +01:00
Qi Xiao
5fa39e1155 Fix the sequencing between closing pipes and setting readerGone.
For some reason this wrong sequencing was only discovered on FreeBSD, and the
test reliably pass on macOS (likely differences in scheduling algorithms).

Also make the bug a bit easier to reproduce on FreeBSD by using an external
command on the reader side. Builtin commands are too quick to execute.
2021-06-25 13:51:52 +01:00
Qi Xiao
78852916a0 Change new tests in str_test.go to use backquote for consistency. 2021-06-24 23:28:10 +01:00
Qi Xiao
82b9bddb15 Test almost all commands correctly bubble output errors.
Also make the helper thatOutputErrorIsBubbled more precise by matching for the
exact error that is thrown.
2021-06-24 23:24:43 +01:00
Qi Xiao
20274d3245 pkg/edit: Test edit builtins bubble output errors.
Two different strategies are used:

- For commands that don't actually depend on the editor (but happens to live
  inside the edit: module), their tests are changed to use the evaltest
  framework.

- For commands that do depend on the editor, a new helper
  testThatOutputErrorIsBubbled is used to test them.

Also fix a bug where edit:complete-getopt does not correctly bubble the
exception thrown from callbacks, and where matchers do not bubble output errors.
2021-06-24 22:46:49 +01:00
Qi Xiao
a3fe485b22 pkg/eval: Test that all value-outputting commands throw on write error. 2021-06-22 00:40:45 +01:00
Qi Xiao
ce08c4a7d5 Throw exception when writing values to a port without a value component.
This is done by generalizing the mechanism used to detect that the reader of
value output has terminated.
2021-06-22 00:35:30 +01:00
Qi Xiao
f4cb00e618 pkg/eval: Test that all byte-outputting commands throw on write error. 2021-06-21 23:39:24 +01:00
Qi Xiao
70cb56b568 Merge branch 'master' into reader-gone 2021-06-20 22:22:37 +01:00
Qi Xiao
75fc7eb839 Don't panic when plugin's Ns variable has wrong type. 2021-06-20 22:13:49 +01:00
Kolby Crouch
917b6eeefc Add plugin support 2021-06-20 21:11:32 +01:00
Qi Xiao
a7c4bbb00f pkg/eval: Improve coverage for compile_value.go.
Most of the remaining untested lines have a dependency on fsutil.GetHome.
2021-06-20 19:14:12 +01:00
Qi Xiao
4776c16b2f Add more test for special forms.
Plus some minor test-related changes.
2021-06-20 18:18:45 +01:00
Qi Xiao
6e75f3468c Move API of pkg/store into pkg/storedefs.
This makes the nodaemon entrypoint not depend on boltdb at all, reducing its
size by 100KB (on darwin-arm64).
2021-06-19 01:54:00 +01:00
Qi Xiao
d6464280f2 Remove direct dependency of pkg/shell on the daemon implementation.
The dependency is injected via a field in shell.Program.

Also add an alternative entrypoint, cmd/nodaemon/elvish, which does not include
the daemon server or client.
2021-06-19 01:43:30 +01:00
Qi Xiao
cfb6134236 Remove daemon:spawn.
The daemon module has never been documented and is not used by any code on GitHub:
https://github.com/search?q=%22use+daemon%22+extension%3Aelv&type=Code&ref=advsearch&l=&l=
arch&l=&l=
2021-06-19 01:07:29 +01:00
Qi Xiao
27eec7c8ee Reorganize the daemon module.
* Move client, spawning and activation code into pkg/daemon/client.

* Move API types into pkg/daemon/daemondefs.
2021-06-19 01:06:11 +01:00
Qi Xiao
6ced40733c pkg/eval: Fix EPIPE on Windows.
The syscall package exposes an EPIPE on Windows, but it's not what Windows APIs
return. The error number 232 is what is semantically EPIPE.
2021-06-18 00:45:25 +01:00
Qi Xiao
53dbece608 Fix style. 2021-06-18 00:16:20 +01:00
Qi Xiao
657b73122f Change all builtin commands writing value output to surface ReaderGone.
Also replace (*Frame).OutputChan with (*Frame).ValueOutput, which returns a
small interface for writing to the value output that is also aware when the
reader is gone.
2021-06-18 00:14:59 +01:00
Qi Xiao
321a4e78eb Merge branch 'master' into reader-gone 2021-06-15 22:09:40 +01:00
Qi Xiao
1fe1497c66 Add appropriate build tag on test for Unix-only exec command. 2021-06-15 20:28:49 +01:00
Qi Xiao
a70059aeb6 Test the exec builtin command. 2021-06-15 20:21:47 +01:00
Qi Xiao
3b7c18c6c5 pkg/eval/vals: Improve test coverage of index.go and iterate_keys.go.
This addresses #1234.
2021-06-15 19:22:58 +01:00
Qi Xiao
2e9e0289cc Make the kind of int, *big.Int and *big.Rat "number". 2021-06-15 19:22:38 +01:00
Qi Xiao
3f0e89d223 pkg/eval/vals: Test expected panics in num.go. 2021-06-15 19:11:57 +01:00
Qi Xiao
2093ac680f Increase coverage of pkg/eval/vals/index_list.go to 100%.
This addresses #1234.
2021-06-15 18:53:31 +01:00
Qi Xiao
83c81cc5b2 Fix unused symbols found by staticcheck.
Also consolidate pkg/sys/testutil_test.go into pkg/sys/select_test.go.
2021-06-15 17:46:31 +01:00
Qi Xiao
b41b6db5cb Fix coverage fluctuation.
A test in navigation_mode.go verifies that a certain key has no effect. It does
that by verifying that the buffer has not changed, which results in a race
condition: the verification might happen after the key is handled, in which
case the test works. But the verification may also happen before the key is
actually handled, in which case the key handling code has not run and thus has
no coverage.

Fix this by queueing another key that would result in an unrelated buffer
change, thus indirectly verifying that the previous key had no effect.
2021-06-15 15:58:00 +01:00
Qi Xiao
5cbb218dad Merge branch 'docset' 2021-06-14 22:50:00 +01:00
Qi Xiao
7d435154f5 Move doc for the epm module into its source. 2021-06-14 22:48:10 +01:00
Qi Xiao
56ce36f1aa Fix the file module's elvdoc.
- Fix broken anchors.

- Fix broken comment block of the pipe command.
2021-06-14 22:18:32 +01:00
Qi Xiao
162ae65b92 Fix elvdoc for file:close and platform:hostname. 2021-06-14 21:57:57 +01:00
Qi Xiao
3204e700ac Fixup for #1329 2021-06-13 22:54:47 +01:00
Kurtis Rader
9a576529a3 Replace ErrArgs with more specific errors
This also replaces the slightly awkward "arguments here" reason with
"argument count" as the "what" for a typical errs.ArityMismatch
exception. It also reformats most of the constructors so that the "what"
is on the same line. This makes `grep errs.ArityMismatch **.go` more
useful as a result.
2021-06-13 22:42:04 +01:00
Qi Xiao
3368744d1b Add comments to pkg/cli/term/reader_windows.go.
Also simplify the logic of AltGr handling. It seems that AltGr and
AltGr+Shift don't actually combine with any other modifiers, so we can
test whether filteredMod is leftCtrl|rightAlt or
leftCtrl|rightAlt|shift, and leave the Mod field unpopulated in the
return value.
2021-06-13 20:41:16 +01:00
kas
903198c96f Remove unnecessary type annotations
Allow AltGr key combinations with modifiers
Remove keyboard layout detection
2021-06-13 16:38:49 +01:00
kas
8be4f8733d Only check for a keyboard layout containing AltGr once 2021-06-13 16:38:49 +01:00
kas
f67ee08b51 Remove unneccessary parentheses 2021-06-13 16:38:49 +01:00
kas
2d8fa34596 Fix wrong syscall arity with GetKeyboardLayout() 2021-06-13 16:38:49 +01:00
kas
3f45103c60 Handle shift-only key combinations the same way as solo keys
This enables uppercase non-ASCII-chars
2021-06-13 16:38:49 +01:00
kas
844a1fedb2 Handle AltGr key combinations on Windows 2021-06-13 16:38:49 +01:00
Qi Xiao
a823eb8fbb Fix a broken link. 2021-06-13 16:27:36 +01:00
Qi Xiao
067c809fc5 Change all builtin commands that write to byte output to surface write errors.
Also replace (*Frame).OutputFile with (*Frame).ByteOutput, which returns a
small interface for writing bytes and converts EPIPE to ReaderGone.
2021-06-11 22:20:27 +01:00
Qi Xiao
3e9e7ce5c8 In elvdoc for to-terminated, use slurp to show byte output that includes NUL. 2021-06-11 14:49:43 +01:00
Kurtis Rader
12c7a08c97 Increase parse/string.go coverage from 44% to 70%
This is an unusual change in that it exists solely to exercise generated
code and thus increase test coverage. On the one hand, if we never care
about the string value of type `RedirMode` then it should be removed
from the stringified types. On the other hand, verifying a redirection
is correctly represented in the output of the parse.pprint...() family
of functions is useful given the importance of I/O redirections in shells
like Elvish.
2021-06-10 09:17:16 +01:00
Qi Xiao
46fa331dca Fixup for #1308. 2021-06-10 09:14:15 +01:00
Kurtis Rader
267e015bd6 Add from-terminated and to-terminated commands
This change makes feeding output to commands which handle NUL terminated
"lines" (e.g., `fzf -read0` or `xargs -0`) extremely fast compared to
using an explicit Elvish loop that does `print $val"\x00"`. Similarly for
handling input from commands that produce NUL terminated "lines" (e.g.,
`find . -print0`) compared to an Elvish loop using `read-upto "\x00"`.

Resolves #1070
Related #1053
2021-06-10 09:06:15 +01:00
Qi Xiao
af3292418f Change math:pow to produce exact results in certain cases; deprecate math:pow10. 2021-06-10 01:47:59 +01:00
Qi Xiao
59e4a7302a Remove outdated TODO on math:round. 2021-06-10 00:11:52 +01:00
Qi Xiao
b7f2457820 Make all rounding functions in math: exactness-preserving.
This fixes #1331.
2021-06-10 00:10:50 +01:00
Qi Xiao
49257cb9fe Run gofmt -s 2021-06-09 01:01:09 +01:00
Qi Xiao
d81bfa69f0 Fix handling of Windows in TestGlob_InvalidUTF8InFilename. 2021-06-09 00:57:36 +01:00
Qi Xiao
bcaa8f5cbf Actually make the test reproduce the crash described in #1220.
The crash doesn't happen right now because the code has been fixed, but the test will
reproduce the crash if the change in glob.go is reverted.
2021-06-09 00:40:55 +01:00
Qi Xiao
941cdf2cdf Fix crash when globbing files with invalid UTF-8 sequences.
This fixes #1220.
2021-06-09 00:36:45 +01:00
Qi Xiao
246c4741c2 Also skip the test if the OS creates the file but mangles the name. 2021-06-09 00:36:18 +01:00
Qi Xiao
e9bcb737ab Make test case crashing too. 2021-06-09 00:31:26 +01:00
Qi Xiao
cfc8f0fe69 Add (failing) regression test for #1220. 2021-06-09 00:10:12 +01:00
Manuel Mendez
25a5c78bf5 Fix oldest command being ignored in edit:command-history &dedup
The loop iteration was stopping at i == 0 and so allCmds[0] was never
examined.
2021-06-08 05:05:18 +01:00
Qi Xiao
cb15a1e28e Fixup for #1332 2021-06-06 22:46:27 +01:00
Kurtis Rader
b8bc076d07 Increase pkg/eval/vars/env_list.go coverage to 100%
Related #1234
2021-06-06 22:43:45 +01:00
Kurtis Rader
a55b83c6f2 Increase pkg/eval/vars/env.go coverage to 100%
Related #1234
2021-06-06 22:39:09 +01:00
Qi Xiao
59b96f27d8
Merge branch 'master' into testutil-test-coverage 2021-06-06 22:03:34 +01:00
Qi Xiao
675812c608 Fixup for #1321. 2021-06-06 22:01:41 +01:00
Qi Xiao
79b5435f8a
Merge pull request #1321 from krader1961/sleep-values
Fix `sleep` handling of the new `num` type
2021-06-06 22:00:47 +01:00
Qi Xiao
c3594f0670 Fixup for #1322. 2021-06-06 21:59:30 +01:00
Kurtis Rader
3a73babdee Increase eawk test coverage to 100%
Related #1234
2021-06-06 21:56:23 +01:00
Qi Xiao
16dc290775
Merge branch 'master' into sleep-values 2021-06-06 21:52:27 +01:00
Qi Xiao
3cf5ab996f pkg/eval/vals: Make Pipe a PseudoStructMap.
It is in theory better implemented as a StructMap because it is a transparent
data type. However, the reflection-based algorithm for StructMap will create a
"kind" field for it, and we don't want to remove the custom kind of Pipe yet, so
this has to be a PseudoStructMap now.
2021-06-06 21:48:39 +01:00
Qi Xiao
a69ce8461e
Merge branch 'master' into pipe-close 2021-06-06 21:40:35 +01:00
Kurtis Rader
ff9341eb91 More error deduplication 2021-06-06 14:54:47 +01:00
Kurtis Rader
f5d38ab3d7 Eliminate duplicate error definitions
In light of the preceding change to address staticcheck lint warnings I
ran this:

    grep 'errors\.New("' **.go |
        sed -e 's/^.*errors\.New("\([^"]*\)".*/\1/' |
        sort | uniq -c | sort -n

Which caused me to notice two errors associated with the builtin `sleep`
command have multiple definitions. It is questionable whether the negative
duration error is justified. I think it should be replaced by the invalid
duration error but decided not to do that in order to limit the scope of
this change.
2021-06-06 14:54:47 +01:00
Kurtis Rader
9345125bd2 staticcheck lint cleanups
Fix two issues found by `staticcheck -tests=false ./...`:

pkg/eval/go_fn.go:155:5: var errNoOptions is unused (U1000)
pkg/persistent/hashmap/hashmap.go:321:2: only the first constant in this group has an explicit type (SA9004)
2021-06-06 14:54:47 +01:00
Qi Xiao
69e9130cf5 pkg/glob: Update TODO about path separator on Windows. 2021-06-06 14:36:38 +01:00
Kurtis Rader
181b663c6a Fix isDrive
I was looking at "TODO" comments that could be eliminated and noticed the
one preceding the sole use of `isDrive()`. Which caused me to notice its
implementation is broken. The `s[1] < 'z'` test should be `s[0] < 'z'`
2021-06-06 14:34:23 +01:00
Kurtis Rader
2b6b11c230 Exercise testutil.MustPipe
I noticed that testutil.MustPipe was not covered by any unit tests. This
converts the handful of places that should use it to do so. This changes
the coverage of pkg/testutil/must.go from 61.5% to 73.1%. There isn't
any way to increase that further without explicitly testing the panic
paths.
2021-06-02 20:29:34 -07:00
Qi Xiao
9361832251 Fixup for #1310 2021-05-31 22:13:24 +01:00
Qi Xiao
45fe3ac2c8
Merge pull request #1310 from krader1961/peach-unit-test
Add test coverage of `peach`
2021-05-31 21:49:24 +01:00
Qi Xiao
e142c6b6a0 Suppress SA2001 for genuine use of empty critical section. 2021-05-31 21:37:26 +01:00
Qi Xiao
641690ed45
Merge branch 'master' into peach-unit-test 2021-05-31 21:33:10 +01:00
Qi Xiao
c39d03e973 Support all number types in the order command.
This fixes #1309.
2021-05-31 21:25:08 +01:00
Qi Xiao
8a2c9a24db pkg/eval/vals: Add an optimized version of UnifyNums for two numbers. 2021-05-31 21:02:12 +01:00
Qi Xiao
e69cde20dc pkg/store: Set options for temp store to improve performance. 2021-05-31 00:19:17 +01:00
Qi Xiao
09a911f2fa Fixup for #1307. 2021-05-31 00:10:26 +01:00
Kurtis Rader
4186e0e77f Add a &cmd-only option to edit:command-history
This is useful when piping the output into a program like `fzf` and more
efficient than dealing with the map. This takes 180.32 ms on my system
(best of five runs):

```
time { edit:command-history &dedup &newest-first | each [hist-entry]{ print $hist-entry[cmd]"\000" } >/dev/null }
```

This option reduces the time to 156.12 ms:

```
time { edit:command-history &dedup &newest-first &cmd-only | each [cmd]{ print $cmd"\000" } >/dev/null }
```

It's not a huge difference but is 13% faster, and should be considerably
faster when combined with a hypothetical `to-lines &null` option I intend
to implement.

Related #1053
2021-05-30 23:49:46 +01:00
Kurtis Rader
20decc5976 Implement edit:command-history &dedup
This implements `&dedup` and `&newest-first` options for
`edit:command-history`. This makes it noticably cheaper to feed unique
command history into external commands like `fzf`.

Related #1053
Fixes #568
2021-05-30 23:49:46 +01:00
Kurtis Rader
f67c7ed387 A couple of TODO cleanups 2021-05-30 00:40:42 +01:00
Kurtis Rader
9b61cdc727 Be consistent about sync.WaitGroup var naming
Also, remove the unused dbStore.Waits() method. This came to my
attention while writing `peach` unit tests.
2021-05-30 00:40:42 +01:00
Kurtis Rader
fee2870564 Lint cleanup: avoid dangling "else { return }"
Also, don't assume the only possible pointer sizes are four and eight bytes.
2021-05-30 00:38:26 +01:00
Kurtis Rader
60bcb27e16 Remove obsolete store API method
While working on issue #568 to add a `&dedup` option to the
`edit:command-history` command I noticed that the `store.Cmd.Cmds()`
method should be removed.
2021-05-30 00:33:37 +01:00
Qi Xiao
cc1a07b28b Fixup for file:truncate. 2021-05-30 00:32:30 +01:00
Supreet
fc28dddb38 file:truncate added to file module, with requested changes 2021-05-30 00:15:43 +01:00
Kurtis Rader
956c4c9d8f Fix sleep handling of the new num type
Fixes #1317
2021-05-23 20:17:51 -07:00
Kurtis Rader
3ded2fb772 Replace prclose and pwclose with file:close
Rather than having specialized commands make a `file:pipe` object
indexable so we can use the generic `file:close` command. This does not
address existing problems; such as builtins not failing when writing to
a `file:pipe` object if the read-end is closed.

Related #1316
2021-05-22 20:55:53 -07:00
Qi Xiao
641f0ebf04 Detect and suppress SIGPIPE caused by the next command in a pipeline exiting early.
This addresses #952.
2021-05-20 00:10:17 +01:00
Qi Xiao
fd70a5a274 pkg/eval/errs: Add ReaderGone error type.
Also fix the error message of SetReadOnlyVar.
2021-05-18 20:34:44 +01:00
Kurtis Rader
8a92716bd9 Add test coverage of peach
This also documents the behavior of `break` and `continue` when used in
the function passed to `peach`.

Related #1234
2021-05-17 19:28:45 -07:00
Qi Xiao
f7a82908e2 Reimplement some math functions to be exactness-preserving.
This addresses #1300.
2021-05-09 20:03:21 +01:00
Qi Xiao
79fe6947cf Reorder test cases in math.go and math_test.go. 2021-05-09 14:40:34 +01:00
Qi Xiao
320b77ea1b pkg/eval/vals: Convert any number type to float64.
This addresses #1300.
2021-05-09 14:32:50 +01:00
Qi Xiao
3d078ec653 pkg/eval/mods/path: Skip symlink tests if unable to create symlinks.
Creating symlinks requires a special permission on Windows, which the
use may not have.

Also remove the support for symlinks in testutil.ApplyDir. Because of
this issue on Windows, any test that requires creating symlinks needs to
be broken out to an individual test case, meaning that symlinks can't be
created alongside other files, so there is less benefit of keeping it
inside the same Dir structure.
2021-05-08 13:22:21 +01:00
Qi Xiao
b80f9ed09e pkg/eval/mods/path: Fix test on Windows. 2021-05-08 02:32:42 +01:00
Qi Xiao
b1d50754e2 Remove the NEXT-RELEASE.md symlink.
GitHub displays symlinks simply as the path of the destination, meaning
that we can't just link to it for the notes of the next release.
2021-05-05 22:26:12 +01:00
Qi Xiao
bf6bcf6117 Minor fixups for #1270. 2021-05-05 22:24:49 +01:00
Kurtis Rader
e2f810048e Add $edit:after-command and $edit:command-duration
The `edit:after-command` hooks are called with a single argument:
a pseudo-map with these keys:

    "command": the command line that was run
    "duration": the execution duration in seconds
    "error": any error that occurred ($nil if no error occurred)

The `edit:command-duration` variable is the elapsed seconds (as a
float64) of the most recently run interactive command.

Resolves #1029
2021-05-05 22:17:19 +01:00
Qi Xiao
91b6f6dd72 Use the integrated persistent package. 2021-05-03 22:17:46 +01:00
Qi Xiao
0a5057a64d Add 'pkg/persistent/' from commit '8ed0fbdb11911ed89129a090bcc1562f3a759481'
git-subtree-dir: pkg/persistent
git-subtree-mainline: 543b123661
git-subtree-split: 8ed0fbdb11
2021-05-03 22:13:15 +01:00
Qi Xiao
543b123661 Add some design notes in eval/vals/num.go. 2021-05-02 01:17:27 +01:00
Qi Xiao
dd3db461ae Update doc for the command mode.
* Emphasize that it's incomplete.

* Remove the TODO for documenting the default binding; it can be
  inspected in an Elvish instance, it is intentionally left
  undocumented.
2021-05-02 00:32:43 +01:00
Qi Xiao
e6027a2d57
Merge pull request #1291 from krader1961/edit-command-doc-fix
Document edit "command" mode
2021-05-01 19:30:38 -04:00
Qi Xiao
2ac9d891ca Improve readability of argument mismatch error message.
* Use 0-based indexing.

* Use more natural-sounding English.

Inspired by #1290.
2021-05-02 00:27:38 +01:00
Qi Xiao
9cd90c49bb Minor fixup for #1274. 2021-05-02 00:22:28 +01:00
Qi Xiao
698d55ef07
Merge branch 'master' into issue-1248 2021-05-01 19:17:17 -04:00
Qi Xiao
7b66e9f104 Minor fixups for #1273.
Also fix a test broken by bad merge.
2021-05-02 00:13:22 +01:00
Qi Xiao
82f1912c5e
Merge branch 'master' into readonly-var-msg 2021-05-01 19:06:39 -04:00
Qi Xiao
5f787d83aa pkg/edit: Make the emptying of PATH part of the common setup. 2021-04-25 23:09:24 +01:00
Qi Xiao
90acb4a242 Minor fixup for path:temp-{dir file}.
* Remove `MatchesRegexp` from eval/vals since it is not part of the
  Elvish value protocol.

* Simplify implementation of value matching in `eval/evaltest`.

* Documentation wording tweaks.
2021-04-25 23:03:44 +01:00
Kurtis Rader
bc37099c92 Add equivalent of mktemp as builtin commands.
This implements `path:temp-dir` and `path:temp-file`.

Resolves #1255
2021-04-25 17:34:23 -04:00
Qi Xiao
210da2abea pkg/edit: Use an empty PATH for nav mode tests. 2021-04-25 15:24:08 +01:00
Kurtis Rader
df3e7a9268 Add a -i CLI option
POSIX shells have a `-i` short option to force interactive mode. Some
programs, such as the `script` command, assume that option is recognized
by the shell it spawns. There isn't any reason elvish shouldn't silently
ignore that option.

Resolves #1292
2021-04-20 16:15:22 -04:00
Qi Xiao
a2ba33f6c5 Remove unneeded tests.
These tests exercise the arity checking logic, which is implemented
generically for every builtin function and does not need to be tested
individually.
2021-04-19 23:49:09 +01:00
Supreet
8f2accb0b9 File module with pipe function. Pipe command marked deprecated in compiler.go and builtin_fn_io.go
Prclose and pwclose with Deprecation marked in specific file. Give
feedback regarding the test cases.

File module now has prclose and pwclose

Wrote test cases for prclose and pwclose, need better test cases

Deprecation for prclose and pwclose marked in respective files.
2021-04-19 18:48:22 -04:00
Kurtis Rader
cfa65953e3 Document edit "command" mode
Fix `//elv:fn` to the correct `//elvdoc:fn` form. Add a little more
information about the "command" mode of the Elvish interactive editor.

Related #971
2021-04-12 21:51:44 -07:00
Qi Xiao
2a1eda6bb0
Fix elvdoc of the src command 2021-04-11 01:17:39 +01:00
Qi Xiao
9b276a3431 Replace references to f{open close} in file module's elvdoc. 2021-04-09 13:03:47 +01:00
Qi Xiao
42d6e94dd7 Remove support for $-exports-. 2021-04-09 00:02:40 +01:00
Qi Xiao
c30a6a2fbe Remove support for using a lone "a=b" for assignment. 2021-04-08 23:57:40 +01:00
Qi Xiao
b53a92b964 Remove all builtin commands deprecated since 0.15.0. 2021-04-08 23:07:50 +01:00
Qi Xiao
318c4c14fd Clean up temporary files properly in the test for the file: module. 2021-04-08 23:07:11 +01:00
Qi Xiao
e1552ab4f5 Minor fixes for the file module:
* Add to release notes.

* Fix the deprecation level of fopen and fclose.

* Fix format of elvdoc and add ref doc.

* Minor style adjustments.
2021-04-08 22:55:33 +01:00
Supreet
77c40b9abb Links file module, marks fopen and fclose deprecation in compiler.go
aand builtin_fn_io.go
2021-04-08 22:45:16 +01:00
Qi Xiao
c2a232a156 Merge branch 'num'
This fixes #241.
2021-04-08 00:43:19 +01:00
Qi Xiao
5eec2c049d Remove special treatment of the builtin: namespace.
This fixes #1227.
2021-04-08 00:42:58 +01:00
Qi Xiao
fd212c1f75 More doc, and add exact-num. 2021-04-07 07:05:08 +01:00
Qi Xiao
a5baad65f8 pkg/eval/vals: Clean up FromGo. 2021-04-06 22:38:56 +01:00
Qi Xiao
6052a4dc4a Remove the "fix int" terminology; just call it "int". 2021-04-06 22:35:58 +01:00
Qi Xiao
e2c4030728 pkg/eval: Handle non-positive step and overflow in the range builtin. 2021-04-06 22:33:02 +01:00
Qi Xiao
5c643181a4 Cleanup, docs and tests. 2021-04-05 20:48:22 +01:00
Qi Xiao
8a7073a20f pkg/cli/mode: Revise a comment. 2021-04-05 15:33:18 +01:00
Kurtis Rader
12980c2719 Some golint cleanups 2021-04-05 15:31:53 +01:00
Qi Xiao
da67ba8a4a Use machine word (int) instead of int64 for fixnum. 2021-04-04 13:37:38 +01:00
Qi Xiao
4612b58759 Support exact integer and rational numbers. 2021-04-04 00:58:53 +01:00
Kurtis Rader
e2759f777b Initialize a command var to $nop~
You cannot assign $nil to a command var so that should not be the initial
value of `var x~`. Instead, assign $builtin:nop~.

Fixes #1248
2021-03-28 22:51:30 -07:00
Qi Xiao
0745463ae7 Merge branch 'query'
This fixes #1051.
2021-03-29 00:10:21 +01:00
Qi Xiao
650161157e pkg/cli/mode: Refactor the handling of default FilterSpec.Maker. 2021-03-29 00:09:32 +01:00
Qi Xiao
b43e5b8793 Rename the query DSL to the filter DSL. 2021-03-28 23:52:25 +01:00
Kurtis Rader
ddf9bf040e Correctly highlight read-only except var
Using a read-only variable as the target of an `except` clause should
highlight just the var name rather than the entire `try...except...`
statement.

Resolves #1258
2021-03-28 22:01:31 +01:00
Qi Xiao
3e512a6dd6 pkg/edit/query: Add test for Highlight.
This package now has 100% unit test coverage.
2021-03-27 02:42:14 +00:00
Qi Xiao
cfb05588c7 Merge branch 'master' into query 2021-03-27 02:06:47 +00:00
Qi Xiao
f5aaba0691 pkg/cli/mode: Deflake stub_test.go by adding an app.Redraw call. 2021-03-27 02:06:35 +00:00
Qi Xiao
dea300f9d6 pkg/{cli edit}: Use the query DSL for location, completion and navigation modes. 2021-03-27 01:55:03 +00:00
Kurtis Rader
1e0885310e Include name in error msg setting a readonly var
When attempting to update a read-only var return an error struct rather
than a simple string (i.e., a Go `error` type).  This makes it possible
to include the var name in the error message.  This builds on commit
a33ecb2d that highlights the offending var name in the stack trace but
does not include the var name in the error message. With this change the
error message includes the offending var name.

Related #255
2021-03-26 18:38:22 -07:00
Qi Xiao
8870defc98 pkg/cli: Refactor how config for custom filters are passed. 2021-03-27 01:21:53 +00:00
Qi Xiao
959120162b pkg/eval: Use cmpd.StringLiteral in one more place.
Also remove an unused method that is now superseded by the cmpd package.
2021-03-19 23:18:42 +00:00
Kurtis Rader
69a8adb2e9 Allow quoted var names in an except... block
Related #1258
2021-03-19 22:59:25 +00:00
Qi Xiao
4ecdb7f278 pkg/cli: Simplify the TTY interface by making it embed term.Writer. 2021-03-19 21:40:32 +00:00
Kurtis Rader
663e04ff75 Fix when cursor is shown by edit:clear
Showing the cursor should only happen after the prompt is redrawn.

Fixes #1238
2021-03-19 21:12:21 +00:00
Qi Xiao
57d3515ec1 Add highlighting for histlist query. 2021-02-27 23:51:49 +00:00
Qi Xiao
d3a38e0414 pkg/ui: Add utility for styling multiple regions in a text.
The code is factored from pkg/edit/highlight and is generally useful.
2021-02-27 23:05:42 +00:00
Qi Xiao
b2591e95a7 Add new edit:clear command.
This fixes #1238.
2021-02-26 00:36:09 +00:00
Qi Xiao
15efaac224 pkg/edit/query: Add tests. 2021-02-25 00:27:52 +00:00
Qi Xiao
d31a7ff166 Use a simple query language in history listing mode. 2021-02-24 00:26:20 +00:00
Qi Xiao
634d71dcba Extract utilities for compound nodes into pkg/parse/cmpd. 2021-02-24 00:02:47 +00:00
Qi Xiao
e3b0b27931 Do not append slash after expanding ~username.
This fixes #1246.
2021-02-23 23:25:48 +00:00
Qi Xiao
9ebb46be0f pkg/cli/tk: Tweak the scrollbar algorithm.
The algorithm now guarantees that the scrollbar size remains the same if the
window size remains the same.
2021-02-21 23:05:41 +00:00
Qi Xiao
a33ecb2da4 When variable cannot set, point to the variable in the stack trace.
This fixes #255.
2021-02-21 11:53:05 +00:00
Qi Xiao
5327ba3521 Make tests compatible with "go test -count n" (n > 1).
The "-count" flag causes the test functions to be invoked multiple times. Since
some tests mutate their test data or some global state, they will fail when
invoked with a count larger than 1.

This commit changes *some* of such tests to either avoid mutating the test data,
or resetting the global state. Some such tests still remain and will be fixed later.
2021-02-17 22:46:32 +00:00
Qi Xiao
fcc005a14a Fix pkg/edit test - one file was left out of that commit. 2021-02-17 22:42:06 +00:00
Qi Xiao
c75c6c5da6 Rename the &bindings option of edit:listing:start-custom to &binding.
It was renamed by accident.

Also add a test for the &binding option.
2021-02-17 22:31:36 +00:00
Qi Xiao
ed854fa667 Remove edit:histlist:toggle-case-sensitivity; do smart-case matching. 2021-02-14 15:52:38 +00:00
Qi Xiao
ba7a72631c Fix readline-binding, and add a test. 2021-02-14 14:41:38 +00:00
Qi Xiao
15af76a22e pkg/edit: Add edit:global-binding for global bindings.
The binding of Esc to close modes is now a default global binding, instead of in
every mode.
2021-02-14 02:05:13 +00:00
Qi Xiao
9f13c3cc6e pkg/cli: Support global bindings.
Global bindings are consulted when an event is not handled by the active widget.
2021-02-14 01:38:34 +00:00
Qi Xiao
3545cb5020 pkg/cli/mode: Fix a flaky completion mode test. 2021-02-13 23:23:23 +00:00
Qi Xiao
0976cacf09 Fix style. 2021-02-13 23:21:39 +00:00
Qi Xiao
62f0f4b580 pkg/cli/mode: Expose the navigation mode as a widget. 2021-02-13 23:21:39 +00:00
Qi Xiao
fb134df955 pkg/cli/mode: Expose the custom listing mode as a widget. 2021-02-13 23:21:39 +00:00
Qi Xiao
50808dc3f2 pkg/cli/mode: Expose the lastcmd mode as a widget. 2021-02-13 23:21:39 +00:00
Qi Xiao
9af7297f75 pkg/cli/mode: Expose the instant mode as a widget. 2021-02-13 23:21:39 +00:00
Qi Xiao
0c17a09de6 pkg/cli/mode: Make Completion, Histlist, Location wrap tk.ComboBox.
Also document that they are based on ComboBox.
2021-02-13 23:21:39 +00:00
Qi Xiao
0931789cde Fix style. 2021-02-13 01:26:13 +00:00
Qi Xiao
9c5669ecdd pkg/cli/mode: Expose the location mode as a widget. 2021-02-13 01:25:05 +00:00
Qi Xiao
be04ccf1fe pkg/cli/mode: Expose the histlist mode as a widget. 2021-02-13 00:54:18 +00:00
Qi Xiao
121232d50c pkg/cli/mode: Expose the completion mode as a widget. 2021-02-12 23:14:29 +00:00
Qi Xiao
52dbfeea66 pkg/cli/mode: Expose the stub mode as a widget. 2021-02-12 23:14:25 +00:00
Qi Xiao
c7dc4d93d3 pkg/cli/mode: Add back the "Mode" prefix to ModeLine and ModePrompt. 2021-02-12 22:37:46 +00:00
Qi Xiao
a785c3b24f pkg/cli: Rewrite histwalk mode as a widget.
Also move it to pkg/cli/mode. Other mode implementations will also be moved into
pkg/cli/mode as they get rewritten as widgets.
2021-02-12 22:34:44 +00:00
Qi Xiao
7f0463a156 pkg/cli: Pass the widget to binding bodies.
A new type, tk.Bindings is defined for bindings. It is always called with the
widget currently handling the event, in addition to the event being handled.
2021-02-12 21:34:47 +00:00
Qi Xiao
c2319fbf59 pkg/cli: Add a SetAddon method to App. 2021-02-12 18:43:34 +00:00
Qi Xiao
8fbbdf4983 pkg/cli: Reorder the methods in App. 2021-02-12 14:19:07 +00:00
Qi Xiao
5e3b9d6431 pkg/cli/tk: De-export test utilities. 2021-02-11 22:34:38 +00:00
Qi Xiao
3767095544 pkg/cli: Further trim down the API
* Remove the utilities {'' Set}{CodeBuffer Addon}.

* De-export the Focuser interface.
2021-02-11 21:50:35 +00:00
Qi Xiao
fd932969d3 pkg/cli: Change ExampleLoop to a test.
This prevents it from appearing in the godoc.
2021-02-11 19:31:53 +00:00
Qi Xiao
0427c536d0 Simplify the API of pkg/cli.
* Move all widget types to a new pkg/cli/tk.

* Move Mode{Line Prompt} to a new pkg/cli/mode.

* Move all packages in pkg/cli/addons to pkg/cli/mode.

* Remove WriteListing.

* Remove StdTTY.

* Rename GetCodeBuffer to CodeBuffer.
2021-02-11 19:24:37 +00:00
Qi Xiao
3539e24f98 pkg/edit: Improve godoc. 2021-02-11 02:28:59 +00:00
Qi Xiao
699f5f45d2 pkg/edit: De-export MakeBindingMap too. 2021-02-11 01:53:28 +00:00
Qi Xiao
278e7d7191 Improve API of pkg/edit.
* De-export BindingMap, as it is only used within the package.

* Improve the godoc of the Editor type.
2021-02-11 01:50:45 +00:00
Qi Xiao
a74ce02c45 Improve the wcwidth package.
* Make the Override function remove the override when given a negative width,
  instead of panicking.

* Make all functions concurrency-safe.

* Improve test coverage to 100%.

This addresses #1234.
2021-02-11 00:47:21 +00:00
Qi Xiao
3c4db682e9 Change path:is-{dir regular} to use Lstat.
This matches their behavior with the documentation regarding symlinks; both
should return false for symlinks.
2021-02-10 23:33:31 +00:00
Qi Xiao
30ab4d4d80 pkg/parse: Introduce a new Query node type.
A Query is a sequence of compound expressions or pairs, like the arguments
and options in a command form. It is not used by any other node type, and is
intended to be a top-level node for representing a small DSL for filtering data,
such as the filter for history mode or location mode.

This addresses #1051.
2021-02-02 02:30:08 +00:00
Qi Xiao
6ef46a7c5f pkg/parse: Refactor tests.
- Consolidate non-error tests and error tests.

- Test different node types using the ParseAs function.
2021-02-02 02:21:02 +00:00
Qi Xiao
c96bfade21 pkg/parse: Small API tweak. 2021-02-01 14:20:56 +00:00
Qi Xiao
72fc2dbe4a Copy and trim down the net/rpc package.
In particular, the dependency on net/http is removed, which removes a
bunch of transitive dependencies.
2021-01-30 23:56:58 +00:00
Qi Xiao
57ce226c65 Bump pkg/buildinfo.Version to 0.16.0 2021-01-30 11:31:52 +00:00
Qi Xiao
585509007e Update for 0.15.0 release.
* Rebrand NEXT-RELEASE.md to the release notes for 0.15.0, and publish it.

* Bump default deprecation level to 15.

* Add download links in website/get/prelude.md.
2021-01-30 11:26:39 +00:00
Qi Xiao
91bdaaf629 Change how version information is overriden.
The mechanism is now documented in PACKAGING.md.

Also refactor tools/buildall.sh to make it easy to make reproducible builds, and
fix tools/cirrus-deploy.sh.
2021-01-28 14:41:34 +00:00
Qi Xiao
e4fa1cf452 Run gofmt -s on pkg/eval/closure.go. 2021-01-27 01:44:28 +00:00
Qi Xiao
196eea21d4 Change module import path to src.elv.sh 2021-01-27 01:30:25 +00:00
Qi Xiao
2dac04dbce Fix highlighting of command names with explicit builtin:. 2021-01-24 16:44:34 +00:00
Qi Xiao
ae98cc5272 Add a new "deprecate" command. 2021-01-24 15:32:24 +00:00
Qi Xiao
b87cc7b5de Add back support for circular module dependency.
This fixes #1226.
2021-01-24 14:10:45 +00:00
Qi Xiao
3bf95ec088 Fix the panic when referencing a module that calls edit:add-var.
This fixes #1225.
2021-01-21 01:05:33 +00:00
Qi Xiao
de562f84d4 Deprecate the $-exports- mechanism in 0.15. 2021-01-19 23:28:38 +00:00
Qi Xiao
37c3c0b0de Deprecate the use of "a=b" for non-temporary assignment in 0.15.
It is still the syntax for temporary assignment; only using it as a standalone
command is deprecated.
2021-01-19 23:28:34 +00:00
Qi Xiao
fbfbef8531 pkg/eval: Move implementation of compile-time deprecation to compiler.go. 2021-01-19 23:20:23 +00:00
Qi Xiao
47d9766f5c Control deprecation warnings with a number instead of a bool.
Previously, to avoid showing deprecation warnings for the next release when the
user is running on HEAD, a boolean CLI flag -show-deprecations is introduced,
and is set to false in the master branch. The idea is that release branches will
have this default to true, so people running released versions will see
deprecations.

However, this means that people running on HEAD will never see any deprecations
unless they use this CLI flag, which is not ideal. This commit replaces the flag
bool -show-deprecations with a numerical -deprecation-level flag, which requests
deprecations that are active as of release 0.X to be shown. The default value of
this flag will be the minor version number of the *last* release, so that people
running HEAD will see as many deprecation warnings as people running the last
release would. This number will be bumped just before releases.
2021-01-19 21:37:36 +00:00
Kurtis Rader
87519a9d9c Fix typo in description of path:is-regular 2021-01-17 04:56:59 +00:00
Qi Xiao
e6e6534fc9 Fix elvdoc for edit:add-vars. 2021-01-17 01:36:06 +00:00
Qi Xiao
d97c989219 Introduce edit:add-var and edit:add-vars.
This addresses #1138.
2021-01-17 01:33:25 +00:00
Qi Xiao
a16cd8dfa6 pkg/eval: Allow "var a:". 2021-01-17 01:17:35 +00:00
Qi Xiao
76c23aa7b0 pkg/edit: Fix formatting of some elvdoc. 2021-01-17 01:13:00 +00:00
Qi Xiao
a1cde7b77b pkg/fsutil: Fix claim_test.go for Windows. 2021-01-17 00:55:51 +00:00
Qi Xiao
629144195b pkg/eval: Fix handling of the global scope in (*Evaler).Eval.
- Do not mutate ev.global if cfg.Global is not nil. This fixes #1223.

- Handle concurrent mutations correctly. This addresses #1138.
2021-01-17 00:36:18 +00:00
Qi Xiao
327561ed0a pkg/daemon: Move the opening of stdin for the daemon to spawn.go. 2021-01-17 00:12:36 +00:00
Qi Xiao
f530a71afc pkg/fsutil: Add more tests for ClaimFile.
The test for concurrent calls uncovered a bug where concurrent calls could
return the same file; fix this by adding a O_EXCL flag.
2021-01-17 00:11:38 +00:00
Kurtis Rader
be712d5405
Introduce the path: module (#1203)
* Introduce the `path:` module

This is based on https://github.com/elves/elvish/pull/1084 by @kolbycrouch
submitted five months ago. It addresses all of the feedback on that
change and includes other documentation and unit test improvements. It
also includes a couple of extensions to the original P.R., such as a
`path:is-abs` command.

I decided to resurrect that change because I want better support for
filesystem path manipulation so that users can replace non-portable
external commands such as `realpath` and `find` with Elvish builtins. This
is a baby step towards that goal.

Related #849

* Add a `path:is-regular` command

This adds a `path:is-regular` command.  This is for symmetry with the
`path:is-dir` command and the glob `[type:regular]` modifier.

It also adds support for symlinks in the `testutil.Applydir` function
and change the path unit test to use it.

* Rename path:real to path:eval-symlinks
2021-01-16 23:21:33 +00:00
Kurtis Rader
d241243fdf Ensure the daemon doesn't have fds open on the tty
The Elvish daemon should not inherit file descriptors open on the tty.
Make the daemon's stdin open on the null device and its stdout/stderr
open on a predictable file.

Fixes #1191
2021-01-16 23:18:38 +00:00