Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto complete recent comint messages.
(defmacro my-save-excursion (&rest forms)
`(let* ((oldp (point))
(oldbuff (current-buffer))
(retval (progn ,@forms)))
(unless (eq (current-buffer) oldbuff) (switch-to-buffer oldbuff))
(goto-char oldp)
etval))
(defun my-helm-comint-input-ring-action (candidate)
"Default action for comint history."
(with-helm-current-buffer
(insert candidate)))
(defvar my-helm-source-comint-input-ring
'((name . "Comint history")
(candidates . (lambda ()
(with-helm-current-buffer
(ring-elements comint-input-ring))))
(action . my-helm-comint-input-ring-action))
"Source that provide helm completion against `comint-input-ring'.")
(defun maybe-switch-to-org ()
(when (and org-src-mode org-src--beg-marker)
(let ((my-marker org-src--beg-marker))
;; (goto-char org-src--beg-marker) didn't work :(
(switch-to-buffer
(marker-buffer my-marker))
(goto-char
(marker-position my-marker)))))
(defun my-comint-anywhere ()
(interactive)
(progn
(my-save-excursion
(maybe-switch-to-org)
(switch-to-buffer (org-babel-initiate-session))
(setq my-comint-input-ring comint-input-ring))
(message "Restored!")
(setq comint-input-ring my-comint-input-ring)
(helm :sources 'my-helm-source-comint-input-ring
:buffer "*helm comint history*")))
(global-set-key (kbd "C-S-r") #'my-comint-anywhere)
(global-set-key (kbd "C-R") #'my-comint-anywhere)
(define-key comint-mode-map (kbd "C-R") #'helm-comint-input-ring)
(define-key comint-mode-map (kbd "C-S-r") #'helm-comint-input-ring)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.