For example, supposing "get-source" does what I need,
Code: Select all
ELISP> (defun say-hi () "Says hi" (message "Hi"))
say-hi
ELISP> (get-source 'say-hi)
"(defun say-hi () "Says hi" (message "Hi"))"
Code: Select all
ELISP> (defun say-hi () "Says hi" (message "Hi"))
say-hi
ELISP> (get-source 'say-hi)
"(defun say-hi () "Says hi" (message "Hi"))"
Code: Select all
(comint-previous-matching-input "^(defun say-hi" 1)
Code: Select all
(defun get-source (regexp)
(interactive (comint-regexp-arg "Previous input matching (regexp): "))
(setq n (comint-search-arg 1))
(let ((pos (comint-previous-matching-input-string-position
(concat "^\\s-*(defun\\s-*" (symbol-name regexp)) n)))
(if (null pos) (error "Not found")
(if (null comint-input-ring-index)
(setq comint-stored-incomplete-input
(funcall comint-get-old-input)))
(setq comint-input-ring-index pos)
(message "History item: %d" (1+ pos))
(comint-delete-input)
(substring-no-properties(ring-ref comint-input-ring pos)))))
Code: Select all
ELISP> (defun say-hi () "Says hi" (message "Hi"))
say-hi
ELISP> (get-source 'say-hi)
"(defun say-hi () \"Says hi\" (message \"Hi\"))"
Code: Select all
ELISP> (defun say-hi () "Says hi" (message "Hi"))
say-hi
ELISP> (symbol-function 'say-hi)
(lambda nil "Says hi"
(message "Hi"))