github.com/xyproto/orbiton/v2@v2.65.12-0.20240516144430-e10a419274ec/funcname.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/xyproto/mode"
     5  )
     6  
     7  // FuncPrefix tries to return the function keyword for the current editor mode, if possible.
     8  // This is not an exhaustive list. It can be used in connection with jumping to definitions.
     9  // If no function prefix is found for this editor mode, an empty string is returned.
    10  // The returned string may be prefixed or suffixed with a blank, on purpose.
    11  func (e *Editor) FuncPrefix() string {
    12  	switch e.mode {
    13  	case mode.Clojure:
    14  		return "defn "
    15  	case mode.Crystal, mode.Nim, mode.Mojo, mode.Python, mode.Scala:
    16  		return "def "
    17  	case mode.GDScript, mode.Go:
    18  		return "func "
    19  	case mode.Kotlin:
    20  		return "fun "
    21  	case mode.Jakt, mode.JavaScript, mode.Koka, mode.Lua, mode.Shell, mode.TypeScript:
    22  		return "function "
    23  	case mode.Terra:
    24  		return "terra "
    25  	case mode.Odin:
    26  		return "proc() "
    27  	case mode.Hare, mode.Rust, mode.V, mode.Zig:
    28  		return "fn "
    29  	case mode.Erlang:
    30  		// This is not "the definition of a function" in Erlang, but should work for many cases
    31  		return " ->"
    32  	case mode.Prolog:
    33  		// This is not "the definition of a function" in Prolog, but should work for many cases
    34  		return " :-"
    35  	}
    36  	return ""
    37  }