I showed you my source code, pls respond
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
7.8 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. #+TITLE: Projects
  2. #+AUTHOR: Christopher James Hayward
  3. #+EMAIL: chris@chrishayward.xyz
  4. #+PROPERTY: header-args:emacs-lisp :tangle projects.el :comments org
  5. #+PROPERTY: header-args:shell :tangle no
  6. #+PROPERTY: header-args :results silent :eval no-export :comments org
  7. #+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  8. #+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  9. #+ATTR_ORG: :width 420px
  10. #+ATTR_HTML: :width 420px
  11. #+ATTR_LATEX: :width 420px
  12. [[../docs/images/2021-02-13-example-ccls.gif]]
  13. An *IDE*[fn:1] like experience or better can be achieved within Emacs using two *Microsoft*[fn:2] open-source initiatives:
  14. + *Debug Adapter Protocol*[fn:3]
  15. + *Language Server Protocol*[fn:4]
  16. * LSP
  17. Support for the *Language Server Protocol*[fn:4] is added to Emacs through the *Lsp mode*[fn:5] package.
  18. #+begin_src emacs-lisp
  19. (use-package lsp-mode
  20. :commands (lsp lsp-deferred)
  21. :custom (lsp-idle-delay (* 5 dotfiles/idle)))
  22. #+end_src
  23. ** UI improvements
  24. *Lsp ui*[fn:6] provides user interface improvements for *Lsp mode*[fn:5].
  25. #+begin_src emacs-lisp
  26. (use-package lsp-ui
  27. :after lsp
  28. :custom (lsp-ui-doc-position 'at-point)
  29. (lsp-ui-doc-delay 0.500))
  30. #+end_src
  31. ** Code completion
  32. Text completion via *Company*[fn:10] =AKA= *Complete Anything*.
  33. #+begin_src emacs-lisp
  34. (use-package company
  35. :after lsp)
  36. #+end_src
  37. Integrate with *Lsp mode*[fn:5] to provide completion candidates through the *Language Server Protocol*[fn:4].
  38. #+begin_src emacs-lisp
  39. (use-package company-lsp
  40. :after (lsp company)
  41. :custom (company-backend 'company-lsp))
  42. #+end_src
  43. * DAP
  44. *Dap mode*[fn:7] provides support for the *Debug Adapter Protocol*[fn:3] inside of Emacs.
  45. #+begin_src emacs-lisp
  46. (use-package dap-mode
  47. :commands (dap-debug))
  48. #+end_src
  49. * Docker
  50. Manage *Docker*[fn:8] containers with *Docker.el*[fn:9].
  51. #+begin_src emacs-lisp
  52. (use-package docker
  53. :commands (docker))
  54. #+end_src
  55. Open the container management screen with =SPC k=.
  56. #+begin_src emacs-lisp
  57. (dotfiles/leader
  58. "k" '(docker :which-key "Docker"))
  59. #+end_src
  60. * Management
  61. Configure *Projectile*[fn:11], a project interaction library for Emacs. It provides a nice set of features for operating on a project level without introducing external dependencies.
  62. #+begin_src emacs-lisp
  63. (use-package projectile
  64. :custom (projectile-project-search-path '("~/.local/source"))
  65. :config (projectile-mode))
  66. #+end_src
  67. * Languages
  68. Support for individual programming languages are implemented here. They can be either:
  69. + LSP / DAP compliant
  70. + Emacs-mode compliant
  71. + Third-party module
  72. ** Go
  73. Golang is supported using the *Debug Adapter Protocol*[fn:3] and *Language Server Protocol*[fn:4].
  74. *** Setup
  75. Get started by installing *gopls*[fn:14].
  76. #+begin_src shell
  77. GO111MODULE=on go get golang.org/x/tools/gopls@latest
  78. #+end_src
  79. **** Overriding the =$GOPATH=
  80. Set the =$GOPATH= environment variable prior to loading, this is to allow modification of the default value from ~$HOME/go~ to ~$HOME/.go~.
  81. #+begin_src emacs-lisp
  82. (setenv "GOPATH" (concat (getenv "HOME") "/.go/"))
  83. #+end_src
  84. **** Adding =$GOBIN= to the =$PATH=
  85. Additionally, include the ~bin~ subdirectory of the =$GOPATH= in the =$PATH= variable, adding compiled golang programs to the systems path.
  86. #+begin_src emacs-lisp
  87. (setenv "PATH" (concat (getenv "GOPATH") "bin:" (getenv "PATH")))
  88. #+end_src
  89. *** Configuration
  90. Finally we can include the *Go-mode*[fn:15] package, adding integration with *Lsp-mode*[fn:5].
  91. #+begin_src emacs-lisp
  92. (use-package go-mode
  93. :hook (go-mode . lsp)
  94. :custom (lsp-go-gopls-server-path "~/.go/bin/gopls"))
  95. #+end_src
  96. Apply some custom behaviour before saving buffers:
  97. + Format buffer
  98. + Organize imports
  99. #+begin_src emacs-lisp
  100. (defun dotfiles/go-hook ()
  101. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  102. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  103. #+end_src
  104. #+begin_src emacs-lisp
  105. (add-hook 'go-mode-hook #'dotfiles/go-hook)
  106. #+end_src
  107. Add a golang source code block structure template with ~<go~:
  108. #+begin_src emacs-lisp
  109. (add-to-list 'org-structure-template-alist '("go" . "src go"))
  110. #+end_src
  111. ** HTTP
  112. Interact with HTTP/HTTPS endpoints using the *Ob-http*[fn:16] package. See how it works in my post *Kanye as a Service*[fn:17].
  113. #+begin_src emacs-lisp
  114. (use-package ob-http
  115. :after org
  116. :config (org-babel-do-load-languages
  117. 'org-babel-load-languages
  118. '((http . t))))
  119. #+end_src
  120. ** C/C++
  121. Add support for the C/C++ family of languages.
  122. + Configure the *CCLS*[fn:18] language server
  123. + Load babel language modules for C/C++
  124. + Create new structure templates for C/C++
  125. * ~<cc~ for C
  126. * ~<cpp~ for C++
  127. #+begin_src emacs-lisp
  128. (use-package ccls
  129. :hook ((c-mode c++-mode objc-mode cuda-mode) .
  130. (lambda ()
  131. (require 'ccls)
  132. (lsp-deferred)))
  133. :config (add-to-list 'org-structure-template-alist '("cc" . "src C"))
  134. (add-to-list 'org-structure-template-alist '("cpp" . "src C++"))
  135. (org-babel-do-load-languages 'org-babel-load-languages '((C . t))))
  136. #+end_src
  137. ** Python
  138. Add support for Python / Python 3 with full support for *DAP*[fn:3] and *LSP*[fn:4].
  139. *** Setup
  140. Install the *pyls*[fn:19] language server.
  141. #+begin_src shell
  142. pip3 install --user "python-language-server[all]"
  143. #+end_src
  144. *Python mode*[fn:20] is an Emacs built in mode for working with Python buffers.
  145. + Load the babel language modules for Python
  146. + Add a structure template with ~<py~
  147. #+begin_src emacs-lisp
  148. (use-package python-mode
  149. :hook (python-mode . lsp-deferred)
  150. :config (require 'dap-python)
  151. (add-to-list 'org-src-lang-modes '("python" . python))
  152. (add-to-list 'org-structure-template-alist '("py" . "src python"))
  153. (org-babel-do-load-languages 'org-babel-load-languages '((python . t)))
  154. :custom (python-shell-interpreter "python3") ;; Required if "python" is not python 3.
  155. (dap-python-executable "python3") ;; Same as above.
  156. (dap-python-debugger 'debugpy))
  157. #+end_src
  158. ** PlantUML
  159. Download and install *PlantUML*[fn:21], a text-based markup language for creating UML diagrams.
  160. + Load the babel language module for *PlantUML*
  161. + Create a structure template with ~<pl~
  162. #+begin_src emacs-lisp
  163. (use-package plantuml-mode
  164. :after org
  165. :custom (plantuml-default-exec-mode 'jar)
  166. (plantuml-jar-path "~/.local/bin/plantuml.jar")
  167. (org-plantuml-jar-path (expand-file-name "~/.local/bin/plantuml.jar"))
  168. (org-startup-with-inline-images t)
  169. :config (add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
  170. (add-to-list 'org-structure-template-alist '("pl" . "src plantuml"))
  171. (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t))))
  172. #+end_src
  173. *** View inside of buffers
  174. Toggle inline images with =SPC t i=.
  175. #+begin_src emacs-lisp
  176. (dotfiles/leader
  177. "ti" '(org-toggle-inline-images :which-key "Images"))
  178. #+end_src
  179. * Resources
  180. [fn:1] https://en.wikipedia.org/wiki/Integrated_development_environment
  181. [fn:2] https://en.wikipedia.org/wiki/Microsoft_and_open_source
  182. [fn:3] https://microsoft.github.io/debug-adapter-protocol
  183. [fn:4] https://microsoft.github.io/language-server-protocol
  184. [fn:5] https://emacs-lsp.github.io/lsp-mode/
  185. [fn:6] https://emacs-lsp.github.io/lsp-ui/
  186. [fn:7] https://emacs-lsp.github.io/dap-mode/
  187. [fn:8] https://docker.com
  188. [fn:9] https://github.com/Silex/docker.el
  189. [fn:10] https://company-mode.github.io/
  190. [fn:11] https://projectile.mx
  191. [fn:12] https://passwordstore.org
  192. [fn:13] https://git.zx2c4.com/password-store/tree/contrib/emacs
  193. [fn:14] https://pkg.go.dev/golang.org/x/tools/gopls
  194. [fn:15] https://emacswiki.org/emacs/GoMode
  195. [fn:16] https://github.com/zweifisch/ob-http
  196. [fn:17] https://chrishayward.xyz/posts/kanye-as-a-service/
  197. [fn:18] https://github.com/MaskRay/ccls
  198. [fn:19] https://pypi.org/project/python-language-server/
  199. [fn:20] https://emacswiki.org/emacs/PythonProgrammingInEmacs
  200. [fn:21] https://plantuml.com
  201. [fn:22] https://github.com/skuro/plantuml-mode