Created
December 27, 2016 21:41
-
-
Save kozikow/d890380e2508ef0a9927448251d04a7f to your computer and use it in GitHub Desktop.
Auto complete recent comint messages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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