38
38
:group 'environment )
39
39
40
40
;;;### autoload
41
- (defcustom add-node-modules-path-command " npm bin"
42
- " Command to find the bin path. To add multiple bin paths, specify a
43
- comma-separated list of commands, e.g. 'pnpm bin, pnpm bin -w'"
44
- :type 'string )
41
+ (defcustom add-node-modules-path-command '(" npm bin" )
42
+ " Command(s) to find the bin path. To add multiple bin paths, simply add
43
+ multiple commands to the list, e.g. \\= '(\" pnpm bin\" \" pnpm bin -w\" )"
44
+ :type '(repeat string)
45
+ :set (lambda (symbol value )
46
+ " Converts a non-list value to a single-element list of the same value.
47
+ This is necessary to be backward compatible, since previous versions of this
48
+ custom var were of type string."
49
+ (set-default symbol (if (listp value) value (list value)))))
45
50
46
51
;;;### autoload
47
52
(defcustom add-node-modules-path-debug nil
48
53
" Enable verbose output when non nil."
49
54
:type 'boolean
50
55
:group 'add-node-modules-path )
51
56
52
- (defun add-node-modules-path/split-comma-separated-list (list-as-string )
53
- " Interprets the provided LIST-AS-STRING argument as comma-separated list of strings
54
- and returns the values as list. Values are trimmed and empty values are removed."
55
- (if (stringp list-as-string)
56
- (seq-filter 's-present? (mapcar 's-trim (s-split " ," list-as-string t )))))
57
+ (defun add-node-modules-path/trim-list-and-elements (list )
58
+ " Trims all string values in LIST and empty / non-string values are removed."
59
+ (if (listp list )
60
+ (seq-filter 's-present? (mapcar 's-trim (seq-filter 'stringp list )))))
57
61
58
62
(defun add-node-modules-path/exec-command (command )
59
- " Executes the given COMMAND and returns a plist containing the command, its shell execution result
60
- and a boolean indicating, whether the execution result denotes a valid directory"
63
+ " Executes the given COMMAND and returns a plist containing the command,
64
+ its shell execution result and a boolean indicating, whether the execution
65
+ result denotes a valid directory"
61
66
(if (and (stringp command) (s-present? command))
62
67
(let ((result (s-chomp (shell-command-to-string command))))
63
68
(list 'command command 'result result 'directory-p (file-directory-p result)))))
64
69
65
70
(defun add-node-modules-path/exec-command-list (command-list )
66
- " Executes all commands in COMMAND-LIST and returns a list of plists containing the various
67
- comnand execution results. Elements in COMMAND-LIST which are not strings are ignored
68
- and will not appear in the result."
71
+ " Executes all commands in COMMAND-LIST and returns a list of plists
72
+ containing the various command execution results. Elements in COMMAND-LIST which
73
+ are not strings are ignoredand will not appear in the result."
69
74
(if (listp command-list)
70
75
(seq-filter 'consp (mapcar 'add-node-modules-path/exec-command command-list))))
71
76
72
77
(defun add-node-modules-path/get-valid-directories (command-executions )
73
- " Filters the provided COMMAND-EXECUTIONS for entries, whose execution result denotes
74
- an existing directory"
78
+ " Filters the provided COMMAND-EXECUTIONS for entries, whose execution result
79
+ denotes an existing directory"
75
80
(if (listp command-executions)
76
81
(let ((filtered (seq-filter '(lambda (elt ) (plist-get elt 'directory-p )) command-executions)))
77
82
(mapcar #' (lambda (elt ) (plist-get elt 'result )) filtered))))
78
83
79
84
(defun add-node-modules-path/get-invalid-executions (command-executions )
80
- " Filters the provided COMMAND-EXECUTIONS for entries, whose execution result denotes
81
- an invalid or non-existing directory"
85
+ " Filters the provided COMMAND-EXECUTIONS for entries, whose execution result
86
+ denotes an invalid or non-existing directory"
82
87
(if (listp command-executions)
83
88
(seq-filter #' (lambda (elt ) (and (plist-member elt 'directory-p ) (not (plist-get elt 'directory-p )))) command-executions)))
84
89
@@ -100,7 +105,7 @@ an invalid or non-existing directory"
100
105
" Run `npm bin` command and add the path to the `exec-path`.
101
106
If `npm` command fails, it does nothing."
102
107
(interactive )
103
- (let* ((commands (add-node-modules-path/split-comma-separated-list add-node-modules-path-command))
108
+ (let* ((commands (add-node-modules-path/trim-list-and-elements add-node-modules-path-command))
104
109
(executions (add-node-modules-path/exec-command-list commands))
105
110
(dirs (add-node-modules-path/get-valid-directories executions)))
106
111
(if (length> dirs 0 )
0 commit comments