this post was submitted on 09 Jan 2025
13 points (100.0% liked)

Emacs

1978 readers
18 users here now

Our infinitely powerful editor.

founded 5 years ago
MODERATORS
 

I am new to emacs (I made a commitment to getting used to linux) & currently intimidated Can you help me out here?

Has anyone here configured Emacs for:

  • Shell-scripting
  • Markdown
  • HTML+CSS
  • Rust

Don't know where to start (I do know the bare-min basics on using Emacs as a text-editor)

you are viewing a single comment's thread
view the rest of the comments
[–] jerkface@lemmy.ca 1 points 6 hours ago* (last edited 6 hours ago)

This is my rust init. Sorry.

;; Fix the damn path
(let ((path (getenv "PATH")))
  (unless (string-match-p "cargo/bin" path)
	(setenv "PATH" (concat "/home/mike/.cargo/bin:" (getenv "PATH")))
	(message "Fixed the damn path")))

;;; Cribbed from https://robert.kra.hn/posts/rust-emacs-setup/

(use-package rustic
  :ensure
  :bind (:map rustic-mode-map
              ("M-j" . lsp-ui-imenu)
              ("M-?" . lsp-find-references)
              ("C-c C-c l" . flycheck-list-errors)
              ("C-c C-c a" . lsp-execute-code-action)
              ("C-c C-c r" . lsp-rename)
              ("C-c C-c q" . lsp-workspace-restart)
              ("C-c C-c Q" . lsp-workspace-shutdown)
              ("C-c C-c s" . lsp-rust-analyzer-status))
  :config
  ;; uncomment for less flashiness
  ;; (setq lsp-eldoc-hook nil)
  ;; (setq lsp-enable-symbol-highlighting nil)
  ;; (setq lsp-signature-auto-activate nil)

  ;; comment to disable rustfmt on save
  (setq rustic-format-on-save t)
  (add-hook 'rustic-mode-hook 'rk/rustic-mode-hook))

(defun rk/rustic-mode-hook ()
  ;; so that run C-c C-c C-r works without having to confirm, but don't try to
  ;; save rust buffers that are not file visiting. Once
  ;; https://github.com/brotzeit/rustic/issues/253 has been resolved this should
  ;; no longer be necessary.
  (when buffer-file-name
    (setq-local buffer-save-without-query t))
  (add-hook 'before-save-hook 'lsp-format-buffer nil t))

(use-package lsp-mode
  :ensure
  :commands lsp
  :custom
  ;; what to use when checking on-save. "check" is default, I prefer clippy
  (lsp-rust-analyzer-cargo-watch-command "clippy")
  (lsp-eldoc-render-all t)
  (lsp-idle-delay 0.6)
  ;; enable / disable the hints as you prefer:
  (lsp-rust-analyzer-server-display-inlay-hints t)
  (lsp-rust-analyzer-display-lifetime-elision-hints-enable "skip_trivial")
  (lsp-rust-analyzer-display-chaining-hints t)
  (lsp-rust-analyzer-display-lifetime-elision-hints-use-parameter-names t)
  (lsp-rust-analyzer-display-closure-return-type-hints t)
  (lsp-rust-analyzer-display-parameter-hints nil)
  (lsp-rust-analyzer-display-reborrow-hints nil)
  :config
  (add-hook 'lsp-mode-hook 'lsp-ui-mode))

(use-package lsp-ui
  :ensure
  :commands lsp-ui-mode
  :custom
  (lsp-ui-peek-always-show t)
  (lsp-ui-sideline-show-hover nil)
  (lsp-ui-doc-enable t))

(use-package company
  :ensure
  :custom
  (company-idle-delay 0.5) ;; how long to wait until popup
  ;; (company-begin-commands nil) ;; uncomment to disable popup
  :bind
  (:map company-active-map
	      ("C-n". company-select-next)
	      ("C-p". company-select-previous)
	      ("M-<". company-select-first)
	      ("M->". company-select-last))
  (:map company-mode-map
	("<tab>". tab-indent-or-complete)
	("TAB". tab-indent-or-complete)))

(use-package yasnippet
  :ensure
  :config
  (yas-reload-all)
  (add-hook 'prog-mode-hook 'yas-minor-mode)
  (add-hook 'text-mode-hook 'yas-minor-mode))

(defun company-yasnippet-or-completion ()
  (interactive)
  (or (do-yas-expand)
      (company-complete-common)))

(defun check-expansion ()
  (save-excursion
    (if (looking-at "\\_>") t
      (backward-char 1)
      (if (looking-at "\\.") t
        (backward-char 1)
        (if (looking-at "::") t nil)))))

(defun do-yas-expand ()
  (let ((yas/fallback-behavior 'return-nil))
    (yas/expand)))

(defun tab-indent-or-complete ()
  (interactive)
  (if (minibufferp)
      (minibuffer-complete)
    (if (or (not yas/minor-mode)
            (null (do-yas-expand)))
        (if (check-expansion)
            (company-complete-common)
          (indent-for-tab-command)))))

(use-package flycheck :ensure)

;;; From https://gagbo.net/post/dap-mode-rust/
(setq dap-cpptools-extension-version "1.5.1")

(with-eval-after-load 'lsp-rust
  (require 'dap-cpptools))

(with-eval-after-load 'dap-cpptools
  ;; Add a template specific for debugging Rust programs.
  ;; It is used for new projects, where I can M-x dap-edit-debug-template

  (dap-register-debug-template
   "livesort"
   (list :type "cppdbg"
         :request "launch"
         :name "livesort"
         :MIMode "gdb"
         :miDebuggerPath "rust-gdb"
         :environment []
         :program "/home/mike/dev/rust/livesort-rs/target/debug/livesort"
         :cwd "/home/mike/dev/rust/livesort-rs"
         :console "external"
         :dap-compilation "cargo build"
         :dap-compilation-dir "/home/mike/dev/rust/livesort-rs"))

  (dap-register-debug-template
   "scroller"
   (list :type "cppdbg"
         :request "launch"
         :name "scroller"
         :MIMode "gdb"
         :miDebuggerPath "rust-gdb"
         :environment []
         :program "/home/mike/dev/rust/scroller/target/debug/scroller"
         :cwd "/home/mike/dev/rust/scroller"
         :console "external"
         :dap-compilation "cargo build"
         :dap-compilation-dir "/home/mike/dev/rust/scroller")))

(with-eval-after-load 'dap-mode
  (setq dap-default-terminal-kind "integrated") ;; Make sure that terminal programs open a term for I/O in an Emacs buffer
  (dap-auto-configure-mode +1))

(provide 'mkp-rust)