Skip to content

Instantly share code, notes, and snippets.

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)
(defun my-helm-comint-input-ring-action (candidate)
"Default action for comint history."
(insert candidate)))
(defvar my-helm-source-comint-input-ring
'((name . "Comint history")
(candidates . (lambda ()
(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 :(
(marker-buffer my-marker))
(marker-position my-marker)))))
(defun my-comint-anywhere ()
(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