term-projectile, contextual-value-manager

This commit is contained in:
Ivan Malison 2015-10-14 01:10:57 -07:00
parent ce24443cf1
commit 0d082bd39d
3 changed files with 89 additions and 5 deletions

View File

@ -535,11 +535,6 @@ The current directory is assumed to be the project's root otherwise."
(bind-key "C-(" 'sp-backward-slurp-sexp smartparens-mode-map)
(bind-key "C-{" 'sp-backward-barf-sexp smartparens-mode-map)))
(defun imalison:start-ansi-term ()
(interactive)
(ansi-term (getenv "SHELL")))
(imalison:prefix-alternatives imalison:term imalison:start-ansi-term ansi-term)
(use-package term
:config
(progn
@ -711,6 +706,7 @@ The current directory is assumed to be the project's root otherwise."
(add-to-list 'load-dirs "~/.emacs.d/load.d")
(defvar site-lisp "/usr/share/emacs24/site-lisp/")
(when (file-exists-p site-lisp) (add-to-list 'load-dirs site-lisp))))
(imalison:prefix-alternatives imalison:term term-projectile ansi-term)
(use-package recentf
;; binding is in helm.
@ -2116,6 +2112,7 @@ window is active in the perspective."
(bind-key "s-<return>" 'toggle-frame-fullscreen)
(bind-key "M-|" 'imalison:shell-command-on-region)
(bind-key "C--" 'undo)
(bind-key "C-c 8" 'imalison:term)
(fset 'global-set-key-to-use-package
(lambda (&optional arg) "Keyboard macro." (interactive "p")

View File

@ -0,0 +1,35 @@
(require 'eieio)
(defclass cvm-contextual-value-manager ()
((identifier-manager :initarg :identifier-manager)
(builder :initarg :builder)))
(defmethod cvm-contextual-value ((cvm cvm-contextual-value-manager))
(let ((identifier (cvm-get-identifier (oref cvm :identifier-manager))))
(or (cvm-get-value (oref cvm :identifier-manager) identifier)
(cvm-build-and-save cvm identifier))))
(defmethod cvm-build-and-save ((cvm cvm-contextual-value-manager) identifier)
(let ((value (cvm-build (oref cvm :builder) identifier)))
(cvm-set-value (oref cvm :identifier-manager) identifier value)
value))
(defclass cvm-identifier-manager () nil
:abstract t)
(defmethod cvm-get-identifier ((generator cvm-identifier-manager))
nil)
(defmethod cvm-get-value ((generator cvm-identifier-manager) identifier)
nil)
(defmethod cvm-set-value ((generator cvm-identifier-manager) identifier value)
nil)
(defclass cvm-builder () nil
:abstract t)
(defmethod cvm-build ((builder cvm-builder) identifier)
nil)
(provide 'contextual-value-manager)

View File

@ -0,0 +1,52 @@
(require 'eieio)
(require 'projectile)
(require 'contextual-value-manager)
(defclass term-projectile-identifier-manager (cvm-identifier-manager eieio-singleton)
((identifier-to-value :initarg :identifier-to-value :initform nil)))
(defmethod cvm-get-identifier ((manager term-projectile-identifier-manager))
(when (projectile-project-p)
(intern (projectile-project-root))))
(defmethod cvm-get-value ((manager term-projectile-identifier-manager) identifier)
(let ((buffer (plist-get (oref manager :identifier-to-value) identifier)))
(when (and buffer (buffer-live-p buffer))
buffer)))
(defmethod cvm-set-value ((manager term-projectile-identifier-manager) identifier value)
(oset manager :identifier-to-value (plist-put (oref manager :identifier-to-value) identifier value)))
(defclass term-builder (cvm-builder eieio-singleton) nil)
(defmethod cvm-build ((builder term-builder) identifier)
(let* ((term-name (build-term-name builder identifier))
(program (getenv "SHELL"))
(directory (if identifier (symbol-name identifier) "~"))
(buffer (get-buffer (term-ansi-make-term term-name program))))
(with-current-buffer buffer
(term-mode)
(term-char-mode)
(let (term-escape-char)
(term-set-escape-char ?\C-x)))
buffer))
(defmethod build-term-name ((builder term-builder) identifier)
(format "term: %s" (symbol-name identifier)))
(defclass projectile-term-manager (cvm-contextual-value-manager eieio-singleton) nil)
(make-instance projectile-term-manager
:builder (make-instance term-builder)
:identifier-manager (make-instance term-projectile-identifier-manager))
(defun term-projectile ()
(interactive)
(switch-to-buffer (cvm-contextual-value (make-instance projectile-term-manager))))
(switch-to-buffer (cvm-contextual-value (make-instance projectile-term-manager)))
(cvm-get-identifier (make-instance term-projectile-identifier-manager))
(provide 'term-projectile)