dotemacs/contrapunctus/cp-prog.el

149 lines
4.3 KiB
EmacsLisp

;;; cp-prog.el --- configuration related to programming
;;; Commentary:
;;
;;; Code:
(require 'cp-prog-elisp)
(require 'cp-prog-c)
(use-package ediprolog
:commands ediprolog-dwim)
(use-package company
:diminish company-mode
:commands global-company-mode
:init (global-company-mode)
:bind ;; ("TAB" . company-indent-or-complete-common)
(:map emacs-lisp-mode-map
("TAB" . company-indent-or-complete-common)
("C-i" . company-indent-or-complete-common))
(:map c-mode-map
("TAB" . company-indent-or-complete-common)
("C-i" . company-indent-or-complete-common))
:config
(add-to-list 'company-backends 'company-irony))
(use-package feature-mode
:mode "\\.feature$")
(defhydra cp-el-eval (:color blue)
("b" eval-buffer "buffer")
("e" eval-defun "defun")
("l" eval-last-sexp "last sexp"))
(defun cp/compile-project (file cmd)
"Locate directory with FILE and run compile command CMD."
(cd (locate-dominating-file default-directory file))
(compile cmd))
(defhydra cp-el (:color blue)
"Emacs Lisp"
("r" ielm "REPL")
("e" cp-el-eval/body "Eval")
("h" helpful-at-point "Help")
("j" xref-find-definitions "Jump to definition")
("d" (funcall-interactively #'eval-defun t) "Debug")
("c" (cp/compile-project "Cask" "cask build") "Compile")
("C" (cp/compile-project "Cask" "cask clean-elc") "clean")
("t" (cp/compile-project "Cask" "cask exec buttercup -L . --traceback pretty") "Test")
("m" magit-status "Magit")
("G" elpher "Elpher")
("o" cp-prog/body "Other language"))
(defhydra cp-scm-eval (:color blue)
("b" geiser-eval-buffer "buffer")
("e" geiser-eval-definition "defun"))
(defhydra cp-guile (:color blue)
"Guile"
("e" cp-scm-eval/body "Eval")
("r" run-guile "REPL")
("m" magit-status "Magit")
("G" elpher "Elpher")
("o" cp-prog/body "Other language"))
(defhydra cp-cs (:color blue)
"CHICKEN Scheme"
("e" cp-scm-eval/body "Eval")
("r" run-chicken "REPL")
("m" magit-status "Magit")
("G" elpher "Elpher")
("o" cp-prog/body "Other language"))
(defhydra cp-ly (:color blue)
"Lilypond"
("c" (cp/compile-project "main.ly" "~/bin/mkly dev") "Compile")
("m" magit-status "Magit")
("G" elpher "Elpher")
("o" cp-prog/body "Other language"))
(defhydra cp-cl-eval (:color blue)
("b" slime-eval-buffer "buffer")
("e" slime-eval-defun "defun"))
(defhydra cp-cl-doc (:color blue)
("d" slime-documentation "slime")
("e" slime-documentation-lookup "CLHS"))
(defhydra cp-cl (:color blue)
"Common Lisp"
("C" slime-connect "connect")
("d" cp-cl-doc/body "Documentation")
("e" cp-cl-eval/body "Eval")
("r" slime "REPL")
("m" magit-status "Magit")
("o" cp-prog/body "Other language")
("G" elpher "Elpher"))
(defhydra cp-prolog (:color blue)
"Prolog"
("o" cp-prog/body "Other language")
("r" ediprolog-dwim "REPL"))
(defhydra cp-prog (:color blue)
"Which language?"
("e" cp-el/body "Emacs Lisp")
("c" cp-cs/body "CHICKEN Scheme")
("g" cp-guile/body "Guile")
("l" cp-ly/body "Lilypond")
("o" cp-cl/body "Common Lisp")
("p" cp-prolog/body "Prolog")
("m" magit-status "Magit")
("G" elpher "Elpher"))
(defun cp/prog-hydra ()
(interactive)
(cond ((or (derived-mode-p 'emacs-lisp-mode 'ielm-mode)
;; ;; Similar problems with this as the f-glob below;
;; ;; e.g. false positive if you have a .dir-locals.el in
;; ;; a project...
;; (f-glob "*.el")
)
(cp-el/body))
(;; (or (locate-dominating-file default-directory "build.scm")
;; (locate-dominating-file default-directory "main.ly"))
(derived-mode-p 'LilyPond-mode)
(cp-ly/body))
((and (featurep 'geiser) geiser-mode)
(cond ((equal 'chicken geiser-impl--implementation)
(cp-cs/body))
((equal 'guile geiser-impl--implementation)
(cp-guile/body))
(t (error "Couldn't detect Scheme implementation."))))
((derived-mode-p 'lisp-mode 'slime-repl-mode)
(cp-cl/body))
((derived-mode-p 'org-mode)
(cp-org/body))
(t (cp-prog/body))))
(define-key prog-mode-map (kbd "M-=") #'cp/prog-hydra)
(define-key dired-mode-map (kbd "M-=") #'cp/prog-hydra)
(define-key dired-mode-map (kbd "=") #'cp/prog-hydra)
(define-key boon-command-map (kbd "=") #'cp/prog-hydra)
(provide 'cp-prog)
;;; cp-prog.el ends here