Add the "Rust programming" section
This commit is contained in:
parent
072b0056b3
commit
cb0d90a10a
105
README.org
105
README.org
@ -883,7 +883,16 @@ minibuffer completion]] for more information.
|
||||
;; https://www.masteringemacs.org/article/understanding-minibuffer-completion
|
||||
(setopt
|
||||
completion-category-overrides '((file (styles basic substring)))
|
||||
completion-styles '(basic flex partial-completion substring)))
|
||||
completion-styles '(basic flex partial-completion substring))
|
||||
|
||||
(defun read-natnum (prompt &optional natnum default hist)
|
||||
"Read NATNUM until it is a natural number and return its value.
|
||||
|
||||
See the function `read-number' for PROMPT (after tweaking), DEFAULT, and HIST."
|
||||
(while (not (natnump natnum))
|
||||
(setq natnum (read-number
|
||||
(format "%s (`%S'): " prompt natnum) default hist)))
|
||||
natnum))
|
||||
|
||||
(when (ensure-package-installation 'marginalia)
|
||||
(marginalia-mode +1))
|
||||
@ -5022,6 +5031,100 @@ if __name__ == "__main__":
|
||||
# PDB: The series of "s" says only here "Uncaught exception".
|
||||
#+end_src
|
||||
|
||||
** [[https://www.rust-lang.org/][Rust programming]]
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: sec:rust-programming
|
||||
:END:
|
||||
|
||||
The link [[https://www.rust-lang.org/tools/install][Install Rust]] shows also how to update the tool chain and the link
|
||||
[[https://rust-lang.github.io/rustup/concepts/components.html][Components]] shows how to add other components to the tool chain. Listing
|
||||
[[lst:read-rust-book]] shows how to read locally [[https://doc.rust-lang.org/book/][The Rust Programming Language]] in
|
||||
the default browser and listing [[lst:rustup-component-list]] lists only the
|
||||
installed components in the Rust tool chain with the results in listing
|
||||
[[lst:rustup-component-list-result]].
|
||||
|
||||
#+caption[Read "The Rust Programming Language" in the default browser]:
|
||||
#+caption: Read "The Rust Programming Language" in the default browser .
|
||||
#+name: lst:read-rust-book
|
||||
#+begin_src shell :eval never-export :results none
|
||||
rustup doc --book
|
||||
#+end_src
|
||||
|
||||
#+caption[List only the installed components in the tool chain]:
|
||||
#+caption: List only the installed components in the tool chain.
|
||||
#+name: lst:rustup-component-list
|
||||
#+header: :wrap "src org -n :eval no"
|
||||
#+begin_src shell :eval never-export :exports both :results output
|
||||
rustup component list --installed
|
||||
#+end_src
|
||||
|
||||
#+caption[The result of listing only the installed components]:
|
||||
#+caption: The result of listing only the installed components.
|
||||
#+name: lst:rustup-component-list-result
|
||||
#+RESULTS:
|
||||
#+begin_src org -n :eval no
|
||||
cargo-x86_64-apple-darwin
|
||||
clippy-x86_64-apple-darwin
|
||||
rust-analyzer-x86_64-apple-darwin
|
||||
rust-docs-x86_64-apple-darwin
|
||||
rust-src
|
||||
rust-std-x86_64-apple-darwin
|
||||
rustc-x86_64-apple-darwin
|
||||
rustfmt-x86_64-apple-darwin
|
||||
#+end_src
|
||||
|
||||
The code formatting in ~rust-ts-mode~ does not support all features of the code
|
||||
formatting of [[https://github.com/rust-lang/rustfmt][rustfmt]] or [[https://doc.rust-lang.org/cargo/commands/cargo-fmt.html][cargo-fmt]] using the default configuration. The
|
||||
installed [[https://github.com/lassik/emacs-format-all-the-code][format-all for Emacs]] library supports both Rust code formatting tools.
|
||||
|
||||
#+caption[Try to work around =rust-ts-mode= indentation quirks]:
|
||||
#+caption: Try to work around =rust-ts-mode= indentation quirks.
|
||||
#+name: lst:go-ts-mode-fix
|
||||
#+begin_src emacs-lisp -n :results silent
|
||||
(when (featurep 'treesit)
|
||||
(defun rsmxspaces (&optional m)
|
||||
"Indent line with M times `rust-ts-mode-indent-offset' spaces."
|
||||
(interactive)
|
||||
(if (not (eq major-mode 'rust-ts-mode))
|
||||
(message "`%s' is not `rust-ts-mode'" major-mode)
|
||||
(read-natnum "indent offset natnum multiplier" m)
|
||||
(move-beginning-of-line nil)
|
||||
(let ((n (* m rust-ts-mode-indent-offset)))
|
||||
(when (re-search-forward "^ *" nil 'noerror 1)
|
||||
(unless (= n (length (match-string 0)))
|
||||
(replace-match (make-string (* n) ? )))))))
|
||||
|
||||
(defun rs0xspaces ()
|
||||
"Indent line with 0 times `rust-ts-mode-indent-offset' spaces."
|
||||
(interactive)
|
||||
(rsmxspaces 0))
|
||||
|
||||
(defun rs1xspaces ()
|
||||
"Indent line with 1 times `rust-ts-mode-indent-offset' spaces."
|
||||
(interactive)
|
||||
(rsmxspaces 1))
|
||||
|
||||
(defun rs2xspaces ()
|
||||
"Indent line with 2 times `rust-ts-mode-indent-offset' spaces."
|
||||
(interactive)
|
||||
(rsmxspaces 2))
|
||||
|
||||
(defun rs3xspaces ()
|
||||
"Indent line with 3 times `rust-ts-mode-indent-offset' spaces."
|
||||
(interactive)
|
||||
(rsmxspaces 3))
|
||||
|
||||
(defun rs4xspaces ()
|
||||
"Indent line with 4 times `rust-ts-mode-indent-offset' spaces."
|
||||
(interactive)
|
||||
(rsmxspaces 4))
|
||||
|
||||
(defun rs5xspaces ()
|
||||
"Indent line with 5 times `rust-ts-mode-indent-offset' spaces."
|
||||
(interactive)
|
||||
(rsmxspaces 5)))
|
||||
#+end_src
|
||||
|
||||
* [[https://github.com/emacs-tw/awesome-emacs#library][Libraries]]
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: sec:libraries
|
||||
|
Loading…
x
Reference in New Issue
Block a user