Procházet zdrojové kódy

Run gofmt.

https://tip.golang.org/doc/go1.19#go-doc
Qi Xiao před 1 rokem
rodič
revize
2e788c846d

+ 8 - 8
pkg/cli/tk/listbox_window.go

@@ -13,17 +13,17 @@ var respectDistance = 2
 // show, and how many initial lines to crop. The window determined by this
 // algorithm has the following properties:
 //
-// * It always includes the selected item.
+//   - It always includes the selected item.
 //
-// * The combined height of all the entries in the window is equal to
-//   min(height, combined height of all entries).
+//   - The combined height of all the entries in the window is equal to
+//     min(height, combined height of all entries).
 //
-// * There are at least respectDistance rows above the first row of the selected
-//   item, as well as that many rows below the last row of the selected item,
-//   unless the height is too small.
+//   - There are at least respectDistance rows above the first row of the selected
+//     item, as well as that many rows below the last row of the selected item,
+//     unless the height is too small.
 //
-// * Among all values satisfying the above conditions, the value of first is
-//   the one closest to lastFirst.
+//   - Among all values satisfying the above conditions, the value of first is
+//     the one closest to lastFirst.
 func getVerticalWindow(state ListBoxState, height int) (first, crop int) {
 	items, selected, lastFirst := state.Items, state.Selected, state.First
 	n := items.Len()

+ 9 - 10
pkg/edit/builtins_test.go

@@ -437,17 +437,16 @@ func TestMoveDotUpDown(t *testing.T) {
 // and periods (.) to indicate trailing runes of words. Indices are also
 // annotated.
 //
-//   cd ~/downloads; rm -rf 2018aug07-pics/*;
-//   ^. ^........... ^. ^.. ^................  (word)
-//   ^. ^.^........^ ^. ^^. ^........^^...^..  (small-word)
-//   ^.   ^........  ^.  ^. ^........ ^...     (alnum-word)
-//   01234567890123456789012345678901234567890
-//   0         1         2         3         4
-//
-//   word boundaries:         0 3      16 19    23
-//   small-word boundaries:   0 3 5 14 16 19 20 23 32 33 37
-//   alnum-word boundaries:   0   5    16    20 23    33
+//	cd ~/downloads; rm -rf 2018aug07-pics/*;
+//	^. ^........... ^. ^.. ^................  (word)
+//	^. ^.^........^ ^. ^^. ^........^^...^..  (small-word)
+//	^.   ^........  ^.  ^. ^........ ^...     (alnum-word)
+//	01234567890123456789012345678901234567890
+//	0         1         2         3         4
 //
+//	word boundaries:         0 3      16 19    23
+//	small-word boundaries:   0 3 5 14 16 19 20 23 32 33 37
+//	alnum-word boundaries:   0   5    16    20 23    33
 var wordMoveTestBuffer = "cd ~/downloads; rm -rf 2018aug07-pics/*;"
 
 var (

+ 5 - 5
pkg/eval/evaltest/evaltest.go

@@ -8,9 +8,9 @@
 //
 // Example:
 //
-//     Test(t,
-//         That("put x").Puts("x"),
-//         That("echo x").Prints("x\n"))
+//	Test(t,
+//	    That("put x").Puts("x"),
+//	    That("echo x").Prints("x\n"))
 //
 // If some setup is needed, use the TestWithSetup function instead.
 package evaltest
@@ -54,7 +54,7 @@ type result struct {
 // When combined with subsequent method calls, a test case reads like English.
 // For example, a test for the fact that "put x" puts "x" reads:
 //
-//     That("put x").Puts("x")
+//	That("put x").Puts("x")
 func That(lines ...string) Case {
 	return Case{codes: []string{strings.Join(lines, "\n")}}
 }
@@ -76,7 +76,7 @@ func (c Case) WithSetup(f func(*eval.Evaler)) Case {
 // DoesNothing returns t unchanged. It is useful to mark tests that don't have
 // any side effects, for example:
 //
-//     That("nop").DoesNothing()
+//	That("nop").DoesNothing()
 func (c Case) DoesNothing() Case {
 	return c
 }

+ 2 - 1
pkg/eval/vals/index_list.go

@@ -101,7 +101,8 @@ func ConvertListIndex(rawIndex any, n int) (*ListIndex, error) {
 }
 
 // Index = Number |
-//         Number ( ':' | '..' | '..=' ) Number
+//
+//	Number ( ':' | '..' | '..=' ) Number
 func parseIndexString(s string, n int) (slice bool, i int, j int, err error) {
 	low, sep, high := splitIndexString(s)
 	if sep == "" {

+ 7 - 7
pkg/eval/vals/struct_map.go

@@ -17,16 +17,16 @@ import (
 //
 // Example:
 //
-//   type someStruct struct {
-//       FooBar int
-//       lorem  string
-//   }
+//	type someStruct struct {
+//	    FooBar int
+//	    lorem  string
+//	}
 //
-//   func (someStruct) IsStructMap() { }
+//	func (someStruct) IsStructMap() { }
 //
-//   func (s SomeStruct) Ipsum() string { return s.lorem }
+//	func (s SomeStruct) Ipsum() string { return s.lorem }
 //
-//   func (s SomeStruct) OtherMethod(int) { }
+//	func (s SomeStruct) OtherMethod(int) { }
 //
 // An instance of someStruct behaves like a read-only map with 3 fields:
 // foo-bar, lorem and ipsum.

+ 1 - 0
pkg/mods/epm/epm.go

@@ -3,5 +3,6 @@ package epm
 import _ "embed"
 
 // Code contains the source code of the epm module.
+//
 //go:embed epm.elv
 var Code string

+ 1 - 0
pkg/mods/readlinebinding/readlinebinding.go

@@ -3,5 +3,6 @@ package readlinebinding
 import _ "embed"
 
 // Code contains the source code of the readline-binding module.
+//
 //go:embed readline-binding.elv
 var Code string

+ 2 - 1
pkg/parse/parse.go

@@ -147,7 +147,8 @@ func startsPipeline(r rune) bool {
 }
 
 // Form = { Space } { { Assignment } { Space } }
-//        { Compound } { Space } { ( Compound | MapPair | Redir ) { Space } }
+//
+//	{ Compound } { Space } { ( Compound | MapPair | Redir ) { Space } }
 type Form struct {
 	node
 	Assignments []*Assignment

+ 4 - 4
pkg/persistent/hashmap/map.go

@@ -25,10 +25,10 @@ type Map interface {
 
 // Iterator is an iterator over map elements. It can be used like this:
 //
-//     for it := m.Iterator(); it.HasElem(); it.Next() {
-//         key, value := it.Elem()
-//         // do something with elem...
-//     }
+//	for it := m.Iterator(); it.HasElem(); it.Next() {
+//	    key, value := it.Elem()
+//	    // do something with elem...
+//	}
 type Iterator interface {
 	// Elem returns the current key-value pair.
 	Elem() (any, any)

+ 4 - 4
pkg/persistent/vector/vector.go

@@ -52,10 +52,10 @@ type Vector interface {
 
 // Iterator is an iterator over vector elements. It can be used like this:
 //
-//     for it := v.Iterator(); it.HasElem(); it.Next() {
-//         elem := it.Elem()
-//         // do something with elem...
-//     }
+//	for it := v.Iterator(); it.HasElem(); it.Next() {
+//	    elem := it.Elem()
+//	    // do something with elem...
+//	}
 type Iterator interface {
 	// Elem returns the element at the current position.
 	Elem() any

+ 4 - 4
pkg/prog/progtest/progtest.go

@@ -9,8 +9,8 @@
 //
 // Example:
 //
-//     Test(t, someProgram,
-//          ThatElvish("-c", "echo hello").WritesStdout("hello\n"))
+//	Test(t, someProgram,
+//	     ThatElvish("-c", "echo hello").WritesStdout("hello\n"))
 package progtest
 
 import (
@@ -58,7 +58,7 @@ func (o output) String() string {
 // For example, a test for the fact that "elvish -c hello" writes "hello\n" to
 // stdout reads:
 //
-//     ThatElvish("-c", "hello").WritesStdout("hello\n")
+//	ThatElvish("-c", "hello").WritesStdout("hello\n")
 func ThatElvish(args ...string) Case {
 	return Case{args: append([]string{"elvish"}, args...)}
 }
@@ -73,7 +73,7 @@ func (c Case) WithStdin(s string) Case {
 // DoesNothing returns c itself. It is useful to mark tests that otherwise don't
 // have any expectations, for example:
 //
-//     ThatElvish("-c", "nop").DoesNothing()
+//	ThatElvish("-c", "nop").DoesNothing()
 func (c Case) DoesNothing() Case {
 	return c
 }

+ 98 - 97
pkg/rpc/server.go

@@ -3,129 +3,129 @@
 // license that can be found in the LICENSE file.
 
 /*
-	Package rpc is a trimmed down version of net/rpc in the standard library.
-	Original doc:
+Package rpc is a trimmed down version of net/rpc in the standard library.
+Original doc:
 
-	Package rpc provides access to the exported methods of an object across a
-	network or other I/O connection.  A server registers an object, making it visible
-	as a service with the name of the type of the object.  After registration, exported
-	methods of the object will be accessible remotely.  A server may register multiple
-	objects (services) of different types but it is an error to register multiple
-	objects of the same type.
+Package rpc provides access to the exported methods of an object across a
+network or other I/O connection.  A server registers an object, making it visible
+as a service with the name of the type of the object.  After registration, exported
+methods of the object will be accessible remotely.  A server may register multiple
+objects (services) of different types but it is an error to register multiple
+objects of the same type.
 
-	Only methods that satisfy these criteria will be made available for remote access;
-	other methods will be ignored:
+Only methods that satisfy these criteria will be made available for remote access;
+other methods will be ignored:
 
-		- the method's type is exported.
-		- the method is exported.
-		- the method has two arguments, both exported (or builtin) types.
-		- the method's second argument is a pointer.
-		- the method has return type error.
+  - the method's type is exported.
+  - the method is exported.
+  - the method has two arguments, both exported (or builtin) types.
+  - the method's second argument is a pointer.
+  - the method has return type error.
 
-	In effect, the method must look schematically like
+In effect, the method must look schematically like
 
-		func (t *T) MethodName(argType T1, replyType *T2) error
+	func (t *T) MethodName(argType T1, replyType *T2) error
 
-	where T1 and T2 can be marshaled by encoding/gob.
-	These requirements apply even if a different codec is used.
-	(In the future, these requirements may soften for custom codecs.)
+where T1 and T2 can be marshaled by encoding/gob.
+These requirements apply even if a different codec is used.
+(In the future, these requirements may soften for custom codecs.)
 
-	The method's first argument represents the arguments provided by the caller; the
-	second argument represents the result parameters to be returned to the caller.
-	The method's return value, if non-nil, is passed back as a string that the client
-	sees as if created by errors.New.  If an error is returned, the reply parameter
-	will not be sent back to the client.
+The method's first argument represents the arguments provided by the caller; the
+second argument represents the result parameters to be returned to the caller.
+The method's return value, if non-nil, is passed back as a string that the client
+sees as if created by errors.New.  If an error is returned, the reply parameter
+will not be sent back to the client.
 
-	The server may handle requests on a single connection by calling ServeConn.  More
-	typically it will create a network listener and call Accept or, for an HTTP
-	listener, HandleHTTP and http.Serve.
+The server may handle requests on a single connection by calling ServeConn.  More
+typically it will create a network listener and call Accept or, for an HTTP
+listener, HandleHTTP and http.Serve.
 
-	A client wishing to use the service establishes a connection and then invokes
-	NewClient on the connection.  The convenience function Dial (DialHTTP) performs
-	both steps for a raw network connection (an HTTP connection).  The resulting
-	Client object has two methods, Call and Go, that specify the service and method to
-	call, a pointer containing the arguments, and a pointer to receive the result
-	parameters.
+A client wishing to use the service establishes a connection and then invokes
+NewClient on the connection.  The convenience function Dial (DialHTTP) performs
+both steps for a raw network connection (an HTTP connection).  The resulting
+Client object has two methods, Call and Go, that specify the service and method to
+call, a pointer containing the arguments, and a pointer to receive the result
+parameters.
 
-	The Call method waits for the remote call to complete while the Go method
-	launches the call asynchronously and signals completion using the Call
-	structure's Done channel.
+The Call method waits for the remote call to complete while the Go method
+launches the call asynchronously and signals completion using the Call
+structure's Done channel.
 
-	Unless an explicit codec is set up, package encoding/gob is used to
-	transport the data.
+Unless an explicit codec is set up, package encoding/gob is used to
+transport the data.
 
-	Here is a simple example.  A server wishes to export an object of type Arith:
+Here is a simple example.  A server wishes to export an object of type Arith:
 
-		package server
+	package server
 
-		import "errors"
+	import "errors"
 
-		type Args struct {
-			A, B int
-		}
+	type Args struct {
+		A, B int
+	}
 
-		type Quotient struct {
-			Quo, Rem int
-		}
+	type Quotient struct {
+		Quo, Rem int
+	}
 
-		type Arith int
+	type Arith int
 
-		func (t *Arith) Multiply(args *Args, reply *int) error {
-			*reply = args.A * args.B
-			return nil
-		}
+	func (t *Arith) Multiply(args *Args, reply *int) error {
+		*reply = args.A * args.B
+		return nil
+	}
 
-		func (t *Arith) Divide(args *Args, quo *Quotient) error {
-			if args.B == 0 {
-				return errors.New("divide by zero")
-			}
-			quo.Quo = args.A / args.B
-			quo.Rem = args.A % args.B
-			return nil
+	func (t *Arith) Divide(args *Args, quo *Quotient) error {
+		if args.B == 0 {
+			return errors.New("divide by zero")
 		}
+		quo.Quo = args.A / args.B
+		quo.Rem = args.A % args.B
+		return nil
+	}
 
-	The server calls (for HTTP service):
+The server calls (for HTTP service):
 
-		arith := new(Arith)
-		rpc.Register(arith)
-		rpc.HandleHTTP()
-		l, e := net.Listen("tcp", ":1234")
-		if e != nil {
-			log.Fatal("listen error:", e)
-		}
-		go http.Serve(l, nil)
+	arith := new(Arith)
+	rpc.Register(arith)
+	rpc.HandleHTTP()
+	l, e := net.Listen("tcp", ":1234")
+	if e != nil {
+		log.Fatal("listen error:", e)
+	}
+	go http.Serve(l, nil)
 
-	At this point, clients can see a service "Arith" with methods "Arith.Multiply" and
-	"Arith.Divide".  To invoke one, a client first dials the server:
+At this point, clients can see a service "Arith" with methods "Arith.Multiply" and
+"Arith.Divide".  To invoke one, a client first dials the server:
 
-		client, err := rpc.DialHTTP("tcp", serverAddress + ":1234")
-		if err != nil {
-			log.Fatal("dialing:", err)
-		}
+	client, err := rpc.DialHTTP("tcp", serverAddress + ":1234")
+	if err != nil {
+		log.Fatal("dialing:", err)
+	}
 
-	Then it can make a remote call:
+Then it can make a remote call:
 
-		// Synchronous call
-		args := &server.Args{7,8}
-		var reply int
-		err = client.Call("Arith.Multiply", args, &reply)
-		if err != nil {
-			log.Fatal("arith error:", err)
-		}
-		fmt.Printf("Arith: %d*%d=%d", args.A, args.B, reply)
+	// Synchronous call
+	args := &server.Args{7,8}
+	var reply int
+	err = client.Call("Arith.Multiply", args, &reply)
+	if err != nil {
+		log.Fatal("arith error:", err)
+	}
+	fmt.Printf("Arith: %d*%d=%d", args.A, args.B, reply)
 
-	or
+or
 
-		// Asynchronous call
-		quotient := new(Quotient)
-		divCall := client.Go("Arith.Divide", args, quotient, nil)
-		replyCall := <-divCall.Done	// will be equal to divCall
-		// check errors, print, etc.
+	// Asynchronous call
+	quotient := new(Quotient)
+	divCall := client.Go("Arith.Divide", args, quotient, nil)
+	replyCall := <-divCall.Done	// will be equal to divCall
+	// check errors, print, etc.
 
-	A server implementation will often provide a simple, type-safe wrapper for the
-	client.
+A server implementation will often provide a simple, type-safe wrapper for the
+client.
 
-	The net/rpc package is frozen and is not accepting new features.
+The net/rpc package is frozen and is not accepting new features.
 */
 package rpc
 
@@ -209,10 +209,11 @@ func isExportedOrBuiltinType(t reflect.Type) bool {
 
 // Register publishes in the server the set of methods of the
 // receiver value that satisfy the following conditions:
-//	- exported method of exported type
-//	- two arguments, both of exported type
-//	- the second argument is a pointer
-//	- one return value, of type error
+//   - exported method of exported type
+//   - two arguments, both of exported type
+//   - the second argument is a pointer
+//   - one return value, of type error
+//
 // It returns an error if the receiver is not an exported type or has
 // no suitable methods. It also logs the error using package log.
 // The client accesses each method using a string of the form "Type.Method",

+ 6 - 5
pkg/sys/ewindows/console.go

@@ -12,11 +12,12 @@ import (
 // https://docs.microsoft.com/en-us/windows/console/readconsoleinput
 //
 // BOOL WINAPI ReadConsoleInput(
-// 	_In_  HANDLE        hConsoleInput,
-// 	_Out_ PINPUT_RECORD lpBuffer,
-// 	_In_  DWORD         nLength,
-// 	_Out_ LPDWORD       lpNumberOfEventsRead
-//   );
+//
+//		_In_  HANDLE        hConsoleInput,
+//		_Out_ PINPUT_RECORD lpBuffer,
+//		_In_  DWORD         nLength,
+//		_Out_ LPDWORD       lpNumberOfEventsRead
+//	  );
 var readConsoleInput = kernel32.NewProc("ReadConsoleInputW")
 
 // ReadConsoleInput input wraps the homonymous Windows API call.

+ 6 - 4
pkg/sys/ewindows/wait.go

@@ -30,10 +30,12 @@ var (
 // timeout.
 //
 // DWORD WINAPI WaitForMultipleObjects(
-//   _In_       DWORD  nCount,
-//   _In_ const HANDLE *lpHandles,
-//   _In_       BOOL   bWaitAll,
-//   _In_       DWORD  dwMilliseconds
+//
+//	_In_       DWORD  nCount,
+//	_In_ const HANDLE *lpHandles,
+//	_In_       BOOL   bWaitAll,
+//	_In_       DWORD  dwMilliseconds
+//
 // );
 func WaitForMultipleObjects(handles []windows.Handle, waitAll bool,
 	timeout uint32) (trigger int, abandoned bool, err error) {

+ 2 - 2
pkg/ui/key.go

@@ -166,9 +166,9 @@ var modifierByName = map[string]Mod{
 
 // ParseKey parses a symbolic key. The syntax is:
 //
-//   Key = { Mod ('+' | '-') } BareKey
+//	Key = { Mod ('+' | '-') } BareKey
 //
-//   BareKey = FunctionKeyName | SingleRune
+//	BareKey = FunctionKeyName | SingleRune
 func ParseKey(s string) (Key, error) {
 	var k Key
 

+ 12 - 12
pkg/ui/mark_lines.go

@@ -6,27 +6,27 @@ type RuneStylesheet map[rune]Styling
 // MarkLines provides a way to construct a styled text by separating the content
 // and the styling.
 //
-// The arguments are groups of either
+// # The arguments are groups of either
 //
 // * A single string, in which case it represents an unstyled line;
 //
-// * Three arguments that can be passed to MarkLine, in which case they are passed
-//   to MarkLine and the return value is used as a styled line.
+//   - Three arguments that can be passed to MarkLine, in which case they are passed
+//     to MarkLine and the return value is used as a styled line.
 //
 // Lines represented by all the groups are joined together.
 //
 // This function is mainly useful for constructing multi-line Text's with
 // alignment across those lines. An example:
 //
-//   var stylesheet = map[rune]string{
-//       '-': Reverse,
-//       'x': Stylings(Blue, BgGreen),
-//   }
-//   var text = FromMarkedLines(
-//       "foo      bar      foobar", stylesheet,
-//       "---      xxx      ------"
-//       "lorem    ipsum    dolar",
-//   )
+//	var stylesheet = map[rune]string{
+//	    '-': Reverse,
+//	    'x': Stylings(Blue, BgGreen),
+//	}
+//	var text = FromMarkedLines(
+//	    "foo      bar      foobar", stylesheet,
+//	    "---      xxx      ------"
+//	    "lorem    ipsum    dolar",
+//	)
 func MarkLines(args ...any) Text {
 	var text Text
 	for i := 0; i < len(args); i++ {

+ 2 - 2
website/cmd/ttyshot/main.go

@@ -6,8 +6,8 @@
 //
 // You can recreate all the ttyshots by running the following from the project top-level directory:
 //
-//   make ttyshot
-//   for f [website/ttyshot/**.spec] { put $f; ./ttyshot $f >/dev/tty 2>&1 }
+//	make ttyshot
+//	for f [website/ttyshot/**.spec] { put $f; ./ttyshot $f >/dev/tty 2>&1 }
 //
 // This assumes working `elvish` and `tmux` programs in $E:PATH.
 package main