This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function find_file | |
| set -q argv[1]; or set argv[1] "." | |
| vterm_cmd find-file (realpath "$argv") | |
| end | |
| function vterm_cmd --description 'Run an Emacs command among the ones been defined in vterm-eval-cmds.' | |
| set -l vterm_elisp () | |
| for arg in $argv | |
| set -a vterm_elisp (printf '"%s" ' (string replace -a -r '([\\\\"])' '\\\\\\\\$1' $arg)) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Static-type function operator | |
| # Usage: | |
| # int_mult = integer %:% function(integer..x, integer..y) { x * y } | |
| `%:%` = function(..type, ..fun) { | |
| ..arg_types = get_arg_types(fun = ..fun) | |
| ..fun = untype_args(fun = ..fun, types = ..arg_types) | |
| function(...) { | |
| ..args = match.call(..fun)[-1] | |
| validate_args(args = ..args, types = ..arg_types) | |
| ..res = eval(..fun(...), envir = environment(..fun)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| range_if = function(.., ..., default = NULL) { | |
| for (expr in list(...)) { | |
| s = substitute(expr) | |
| if (length(s) < 3 || s[[1]] != as.symbol("~")) { | |
| stop("Invalid argument. Use `condition ~ expression`") | |
| } | |
| if (isTRUE(eval(s[[2]]))) return(eval(s[[3]])) | |
| } | |
| default | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| `%||%` = function(x, y) { | |
| if (!identical(x, FALSE)) x else y | |
| } | |
| toggle = function(fun, env_var = "env", dev_env = "dev") { | |
| if (Sys.getenv(env_var) == dev_env) fun else FALSE | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Imports a namespace under an alias | |
| # (equivalent of Python's `import ... as ...`) | |
| importAs = function(namespace, alias) { | |
| namespace::registerNamespace(name = alias, env = asNamespace(namespace)) | |
| } | |
| # Imports function(s) from a namespace (including unexported functions) | |
| # to the global namespace | |
| # (equivalent of Python's `import ... from ...`) | |
| importFrom = function(namespace, functions) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(magrittr) | |
| hex_to_rgb = function(color_list) { | |
| mapply(function(clr, i) { | |
| clr %>% | |
| substring(c(2, 4, 6), c(3, 5, 7)) %>% | |
| paste0("0x", .) %>% | |
| strtoi() %>% | |
| `/`(256) %>% | |
| paste(collapse = ",") %>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| `%>%` = function(par, fun) { | |
| s = substitute(fun) | |
| fun.name = s[[1]] | |
| fun.args = as.list(s) | |
| fun.args[[1]] = par | |
| do.call(deparse(fun.name), fun.args) | |
| } | |