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

Emacs

2275 readers
20 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)

top 20 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 36 minutes ago* (last edited 35 minutes 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)

[–] [email protected] 1 points 4 hours ago

Eglot + various system lsps

[–] [email protected] 1 points 4 hours ago

Shell-scripting

Isn't shell-script-mode available in vanilla installation? For me it automatically gets enabled when I open .sh file

Markdown

https://www.emacswiki.org/emacs/MarkdownMode

HTML+CSS

Haven't written these in a while, but I expect there will be modes for them

Rust

https://github.com/rust-lang/rust-mode?tab=readme-ov-file#melpa

And in general:
https://www.emacswiki.org/emacs/InstallingPackages
and
https://www.gnu.org/software/emacs/manual/html_node/emacs/Customization-Groups.html

[–] [email protected] 1 points 12 hours ago

I use org mode for everything. org-babel let's you embed code and execute it in the document or tangle code blocks into external scripts.

[–] [email protected] 1 points 13 hours ago
[–] [email protected] 3 points 19 hours ago (1 children)

Hello! Welcome to Emacs!

Contrary to the other commenters, I would suggest starting with an out-of-the-box Emacs and only adding the things you need, as you need them.

As for your question, could you provide more detail about your expectations?

In the absence of it, I'll give you some generic responses:

[–] [email protected] 1 points 3 hours ago (1 children)

How about Org-Mode as a viable Markdown functionality/editor etc...?

[–] [email protected] 1 points 3 hours ago* (last edited 3 hours ago)

Yes org-mode is an excellent alternative to markdown. Emacs offers a ton of features out of the box related to org-mode. However it is intrinsically tied with Emacs, so if you aren't sure about Emacs, then I wouldn't suggest using org-mode as a replacement just yet. I do encourage you to give it a shot though!

[–] [email protected] 6 points 23 hours ago (1 children)

I used to maintain my own Emacs config, but I switched to Doom years ago and never looked back. I appreciate the community aspect that lets it be better integrated and tested than I had time to manage on my own.

I use it as my primary environment for everything you mentioned and its excellent. The initial setup is fairly easy too.

And because it's Emacs, if there's something you don't like, you can change it! 😄

[–] [email protected] 5 points 23 hours ago* (last edited 23 hours ago) (1 children)

Hmmmm, I'll give it a shot😅 After a long while with DoomEmacs, I'll probably attempt at creating my own configs & share it here in this community.

Now that we're here, how about Spacemacs ?

[–] [email protected] 2 points 17 hours ago

Cool! Give it a go! Do you know about the Emacs Wiki? It was a pretty good resource many years ago when I had my own config. Not sure how it is these days though, but you might find some useful stuff there.

As for Spacemacs, I never got into it. At the time I found it more complicated than my own setup and a bit more confusing. I know a lot of people liked it though, and it was the first starter kit I'm aware of that really took off, so it might be worth a look!

[–] [email protected] 2 points 19 hours ago

Base Emacs 29 will do a lot for you in those areas, especially with rust-ts-mode (Treesitter powered Rust mode), Markdown mode, Company (a completion tool), and Eglot (lsp server client). I also recommend adding Which-Key to help figure out the bindings in different modes. Built-in eshell is great for scripting / terminal needs.

For a kickstarter config, System Crafters' is pretty nice and will mostly keep you to built ins with good documentation of why they chose things. https://github.com/SystemCrafters/crafted-emacs/ and they have a Rust example config using their modules in their examples.

Doom Emacs and Space Emacs are cool too to show some possibilities and get a full featured ide earlier, but there those setups due add their own learning steps.

[–] [email protected] 1 points 17 hours ago

I second looking at System Crafters' resources. One thing that helped me was their emacs from scratch video series.

And as a heavy Markdown user, I initially built my config around Markdown. But several years later I've found I now use org-mode almost exclusively instead. They both fill the same niche in my workflow, but org-mode can do a lot more.

[–] [email protected] 4 points 23 hours ago (1 children)

If you're new(ish) to Emacs, I would strongly suggest using a kit like Doom Emacs. It sets up some modern defaults, and makes it far, far simpler to set up a good environment for whatever languages you want. And the wonderful thing is that you can keep using Doom!

[–] [email protected] 2 points 23 hours ago (2 children)

Are you sure a newbie-like me should be using doom-emacs ?

[–] [email protected] 1 points 8 hours ago (1 children)

Yes. It makes configuring Emacs a whole lot simpler than vanilla Emacs.

[–] [email protected] 1 points 2 hours ago (1 children)

I disagree with this. I tried Doom when I first started using Emacs and yes, it gets you there faster, but it's extremely opinionated and essentially has it's own configuration language. I found that confusing when trying to learn how Emacs works, as there is "the Emacs" way, and then "the Doom" way.

[–] [email protected] 1 points 1 hour ago (1 children)

If your goal is to get started with Emacs, and have a lot of things pre-configured, Doom will get you there much faster than starting from scratch. It is opinionated, yes, and configuring it is somewhat different than building from scratch, but I would never recommend starting Emacs from scratch for someone new to it, unless I happen to know they like to suffer.

[–] [email protected] 2 points 1 hour ago

@algernon @kyoji I disgree. Doom is highly opinionated, and eschews emacs norms and defaults willfully and regularly. There are lots of good newbie-friendly modern setups that will get you off the ground and give you a good foundation to start personal customizations. Doom is not one of them. As well teach someone to drive by ordering them an Uber. Driven by someone who uses both feet.

[–] [email protected] 1 points 11 hours ago

Yes, you should absolutely go with DOOM Emacs.

I'm also an Emacs newb (been using it for 1 year). DOOM made getting into Emacs actually approachable.

Good luck on your journey!