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.
 
 
 

7.8 KiB

Projects

/chris/dotfiles/src/commit/b2a674822bf500171e7623dffc013a23b5519469/docs/images/2021-02-13-example-ccls.gif

An IDE1 like experience or better can be achieved within Emacs using two Microsoft2 open-source initiatives:

  • Debug Adapter Protocol3

  • Language Server Protocol4

LSP

Support for the Language Server Protocol4 is added to Emacs through the Lsp mode5 package.

(use-package lsp-mode
  :commands (lsp lsp-deferred)
  :custom (lsp-idle-delay (* 5 dotfiles/idle)))

UI improvements

Lsp ui6 provides user interface improvements for Lsp mode5.

(use-package lsp-ui
  :after lsp
  :custom (lsp-ui-doc-position 'at-point)
          (lsp-ui-doc-delay 0.500))

Code completion

Text completion via Company7 AKA Complete Anything.

(use-package company
  :after lsp)

Integrate with Lsp mode5 to provide completion candidates through the Language Server Protocol4.

(use-package company-lsp
  :after (lsp company)
  :custom (company-backend 'company-lsp))

DAP

Dap mode8 provides support for the Debug Adapter Protocol3 inside of Emacs.

(use-package dap-mode
  :commands (dap-debug))

Docker

Manage Docker9 containers with Docker.el10.

(use-package docker
  :commands (docker))

Open the container management screen with SPC k.

(dotfiles/leader
  "k" '(docker :which-key "Docker"))

Management

Configure Projectile11, 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 gopls12.

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-mode13 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

Interact with HTTP/HTTPS endpoints using the Ob-http14 package. See how it works in my post Kanye as a Service15.

(use-package ob-http
  :after org
  :config (org-babel-do-load-languages
            'org-babel-load-languages
            '((http . t))))

C/C++

Add support for the C/C++ family of languages.

  • Configure the CCLS16 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 pyls17 language server.

pip3 install --user "python-language-server[all]"

Python mode18 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 PlantUML19, 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"))

Resources