8.5 KiB
Projects
An IDE1 like experience or better can be achieved within Emacs using two Microsoft2 open-source initiatives:
LSP
DAP
Docker
Passwords
Pass11 makes managing passwords extremely easy, encrypring them in a file structure and providing easy commands for generating, modify, and copying passwords. Password-store.el12 provides a wrapper for the functionality within Emacs.
(use-package password-store :custom (password-store-dir dotfiles/passwords))
Configure keybindings behind SPC p
.
-
Copy with
p
-
Rename with
r
-
Generate with
g
(dotfiles/leader "p" '(:ignore t :which-key "Passwords") "pp" '(password-store-copy :which-key "Copy") "pr" '(password-store-rename :which-key "Rename") "pg" '(password-store-generate :which-key "Generate"))
Management
Configure Projectile13, a project interaction library for Emacs. It provides a nice set of features for operating on a project level without introducing external dependencies.
(use-package projectile :custom (projectile-project-search-path '("~/.local/source")) :config (projectile-mode))
Languages
Support for individual programming languages are implemented here. They can be either:
-
LSP / DAP compliant
-
Emacs-mode compliant
-
Third-party module
Go
Golang is supported using the Debug Adapter Protocol3 and Language Server Protocol4.
Setup
Get started by installing gopls14.
GO111MODULE=on go get golang.org/x/tools/gopls@latest
Overriding the $GOPATH
Set the $GOPATH
environment variable prior to loading, this is to allow modification of the default value from $HOME/go
to $HOME/.go
.
(setenv "GOPATH" (concat (getenv "HOME") "/.go/"))
Adding $GOBIN
to the $PATH
Additionally, include the bin
subdirectory of the $GOPATH
in the $PATH
variable, adding compiled golang programs to the systems path.
(setenv "PATH" (concat (getenv "GOPATH") "bin:" (getenv "PATH")))
Configuration
Finally we can include the Go-mode15 package, adding integration with Lsp-mode5.
(use-package go-mode :hook (go-mode . lsp) :custom (lsp-go-gopls-server-path "~/.go/bin/gopls"))
Apply some custom behaviour before saving buffers:
-
Format buffer
-
Organize imports
(defun dotfiles/go-hook () (add-hook 'before-save-hook #'lsp-format-buffer t t) (add-hook 'before-save-hook #'lsp-organize-imports t t))
(add-hook 'go-mode-hook #'dotfiles/go-hook)
Add a golang source code block structure template with <go
:
(add-to-list 'org-structure-template-alist '("go" . "src go"))
HTTP
C/C++
Add support for the C/C++ family of languages.
-
Configure the CCLS18 language server
-
Load babel language modules for C/C++
-
Create new structure templates for C/C++
-
<cc
for C -
<cpp
for C++
-
(use-package ccls :hook ((c-mode c++-mode objc-mode cuda-mode) . (lambda () (require 'ccls) (lsp-deferred))) :config (add-to-list 'org-structure-template-alist '("cc" . "src C")) (add-to-list 'org-structure-template-alist '("cpp" . "src C++")) (org-babel-do-load-languages 'org-babel-load-languages '((C . t))))
Python
Add support for Python / Python 3 with full support for DAP3 and LSP4.
Setup
Install the pyls19 language server.
pip3 install --user "python-language-server[all]"
Python mode20 is an Emacs built in mode for working with Python buffers.
-
Load the babel language modules for Python
-
Add a structure template with
<py
(use-package python-mode :hook (python-mode . lsp-deferred) :config (require 'dap-python) (add-to-list 'org-src-lang-modes '("python" . python)) (add-to-list 'org-structure-template-alist '("py" . "src python")) (org-babel-do-load-languages 'org-babel-load-languages '((python . t))) :custom (python-shell-interpreter "python3") ;; Required if "python" is not python 3. (dap-python-executable "python3") ;; Same as above. (dap-python-debugger 'debugpy))
PlantUML
Download and install PlantUML21, a text-based markup language for creating UML diagrams.
-
Load the babel language module for PlantUML
-
Create a structure template with
<pl
(use-package plantuml-mode :after org :custom (plantuml-default-exec-mode 'jar) (plantuml-jar-path "~/.local/bin/plantuml.jar") (org-plantuml-jar-path (expand-file-name "~/.local/bin/plantuml.jar")) (org-startup-with-inline-images t) :config (add-to-list 'org-src-lang-modes '("plantuml" . plantuml)) (add-to-list 'org-structure-template-alist '("pl" . "src plantuml")) (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t))))
View inside of buffers
Toggle inline images with SPC t i
.
(dotfiles/leader "ti" '(org-toggle-inline-images :which-key "Images"))