command - Cannot add function in Emacs -
i have started using emacs , trying add function split entered sentence list of words (split 1 space):
(defun split-by-one-space (string) ; from: http://cl-cookbook.sourceforge.net/strings.html "returns list of substrings of string divided 1 space each. note: 2 consecutive spaces seen if there empty string between them." (loop = 0 (1+ j) j = (position #\space string :start i) collect (subseq string j) while j)) (defun myfn (ss) "documentation of fn: added" (interactive "s\enter words: ") (message "read: %s" (split-by-one-space ss)))
i have kept above in folder ~/.emacs.d/init.el
in there 2 other functions picked , executed. above function 'myfn'
, however, not found when try execute m-x
method. function 'split-by-one-space'
not found.
where problem , how can solve it?
edit:
starting emacs command "emacs --debug-init
" shows following error:
(invalid-read-syntax "#")
apparently \#space
not recognized in emacs lisp. replaced '?\ '
, error went away. function myfn available executing. however, on executing it, following error shown:
symbol's function definition void: loop
apparently loop part needs rewritten in emacs lisp.
#\space
not valid elisp , cause read-error, emacs stop processing file @ point. want write ?\s
or ?\
instead, syntax used in elisp character literals.
after that, you'll see loop
not known emacs. want use cl-loop
instead, provided cl-lib
package, not need rename loop
cl-loop
additionally need add
(require 'cl-lib)
earlier. subseq
, positions
not known elisp , you'll need use cl-subseq
, cl-position
instead (also provided cl-lib
).
Comments
Post a Comment