~jman/dotfiles

eb3778b1b06c4e94e62bcb541ba43cdf9ddc6ba7 — jman 5 days ago a8c0c1e master
Update Emacs/Doom config and build guide
6 files changed, 125 insertions(+), 78 deletions(-)

M doom/.config/doom/config.el
M doom/.config/doom/packages.el
M doom/README.md
M doom/WTFs.md
R emacs/{Dockerfile.emacs-native-comp => Dockerfile}
M emacs/README.md
M doom/.config/doom/config.el => doom/.config/doom/config.el +21 -12
@@ 106,8 106,6 @@

(setq fill-column 100)

(load! "mu4e-config" doom-private-dir)

;; header for blog posts
(defun create_blog_stub ()
  "Create a blog post stub"


@@ 129,14 127,6 @@
(setq wordreference-source-lang "en")
(setq wordreference-target-lang "it")

;; configure RSS sync server for elfeed
;; (load! "mu4e-config" doom-private-dir)
;; (after! mu4e
;;   (jman/load-org-file "contexts.org")
(load! "elfeed-config" doom-private-dir)
;; and automatically update feed when opening elfeed
(add-hook! 'elfeed-search-mode-hook 'elfeed-update)

(use-package! guru-mode
  :init
  ;; (guru-global-mode +1)


@@ 200,5 190,24 @@ Put it into the kill ring."
    (kill-new location)
    (message location)))

(load! "wallabag-config" doom-private-dir)
(add-hook 'wallabag-after-render-hook 'wallabag-search-update-and-clear-filter)
(when (string= (system-name) "nyarlathotep")
  ;; configure mu4e
  (load! "mu4e-config" doom-private-dir)

  ;; configure wallabag
  (load! "wallabag-config" doom-private-dir)
  (add-hook 'wallabag-after-render-hook 'wallabag-search-update-and-clear-filter)

  ;; configure RSS sync server for elfeed
  ;; (load! "mu4e-config" doom-private-dir)
  ;; (after! mu4e
  ;;   (jman/load-org-file "contexts.org")
  (load! "elfeed-config" doom-private-dir)
  ;; and automatically update feed when opening elfeed
  (add-hook! 'elfeed-search-mode-hook 'elfeed-update))

;; configure vertico extension
;; see: https://kristofferbalintona.me/posts/202202211546/#vertico
;;(setq vertico-multiform-categories
;; '((consult-grep grid)
;;   (consult-location grid)))

M doom/.config/doom/packages.el => doom/.config/doom/packages.el +7 -6
@@ 64,8 64,6 @@

(package! wordreference)

(package! elfeed-protocol)

;; too much visual assistance becomes annoying
(package! lsp-ui :disable t)



@@ 87,7 85,10 @@
;;            :branch "master"
;;            :files ("eglot.el")))

(package! wallabag
  :recipe (:host github
           :repo "chenyanming/wallabag.el"
           :files ("*.el" "*.alist" "*.css")))
;; packages to load only on this host
(when (string= (system-name) "nyarlathotep")
  (package! elfeed-protocol)
  (package! wallabag
    :recipe (:host github
             :repo "chenyanming/wallabag.el"
             :files ("*.el" "*.alist" "*.css"))))

M doom/README.md => doom/README.md +8 -0
@@ 1,5 1,13 @@
# Doom Emacs tips

## Install

```sh
export EMACSDIR=~/.doom
git clone --depth 1 --single-branch https://github.com/doomemacs/doomemacs ~/.doom
~/.doom/bin/doom install
```

How to enable and disable `lsp` and `lsp-ui` features: https://github.com/emacs-lsp/lsp-mode/blob/master/docs/tutorials/how-to-turn-off.md

### How to Do a Project-wide Search & Replace in Doom Emacs

M doom/WTFs.md => doom/WTFs.md +71 -31
@@ 1,3 1,31 @@
## Doom clean

Is only intended to clean your `config` directory, not the Doom installation directory. So all .elc files from `straight` are not affected by this command.

To remove all cache created from `straight` packages, manually delete them with
```
$ find $EMACSDIR/.local/straight/build-xx.yy.zz/ -name '*.elc' -delete
```

then rebuild that cache with `doom build`

## Doom compile

Doesn't succeed anymore, reports errors that I can't figure out how to fix. After running `doom compile`, invoking the cli again is broken
```
$ doom
Error: a subcommand is required
x There was an unexpected runtime error
  Message: File is missing
  Details: ("Cannot open load file" "No such file or directory" "/home/$USER/.doom/bin/make/completions")
  Backtrace:
    ...
  ! Wrote extended backtrace to ~/.doom/.local/logs/cli.doom.220801142638.339577.error
```

Run `doom clean` to fix that.


## Change dictionary used for autocompletion

Emacs uses `ispell` (a.k.a. `aspell`) for spell checking:


@@ 54,46 82,58 @@ Select the new default wordlist: `sudo select-default-wordlist`

## Using vertico

After switching from `ivy` to `vertico` I see two behaviours I'd like to change.
After switching from `ivy` to `vertico` I see behaviours I'd like to change.

1. Change search results view of `+default/search-project-for-symbol-at-point` / `+default/search-project` to a more compact view, like it was with `ivy`, example:

From this:

```
  README.md
10:cargo run -- -n <repo_name> -o <repo_owner> -t <srht_tracker_id>
  src/main.rs
16:    gh_repo_owner: String,
52:            opt.gh_repo_owner.to_owned(),
132:        .get_gh_issues(opt.gh_repo_owner, opt.gh_repo_name, Some(50))
  src/http/github.rs
14:        repo_owner: String,
20:            repo_owner: repo_owner.to_owned(),
88:        repo_owner: String,
94:            repo_owner: repo_owner.to_owned(),
```

to this:

```
README.md:10:      cargo run -- -n <repo_name> -o <repo_owner> -t <srht_tracker_id>
src/main.rs:16:    gh_repo_owner: String,
src/main.rs:52:            opt.gh_repo_owner.to_owned(),
src/main.rs:132:        .get_gh_issues(opt.gh_repo_owner, opt.gh_repo_name, Some(50))
src/github/queries.rs:10:        pub repo_owner: String,
src/github/queries.rs:19:        #[arguments(owner = &args.repo_owner, name = &args.repo_name)]
src/github/queries.rs:79:        pub repo_owner: String,
```

Can be done by enabling `vertico-grid-mode` but that then breaks the menu of `M-x`. Vertico should be configured through the `vertico-multiform-mode` extension, see [here](https://github.com/minad/vertico/blob/main/extensions/vertico-multiform.el). 
    From this:

    ```
      README.md
    10:cargo run -- -n <repo_name> -o <repo_owner> -t <srht_tracker_id>
      src/main.rs
    16:    gh_repo_owner: String,
    52:            opt.gh_repo_owner.to_owned(),
    132:        .get_gh_issues(opt.gh_repo_owner, opt.gh_repo_name, Some(50))
      src/http/github.rs
    14:        repo_owner: String,
    20:            repo_owner: repo_owner.to_owned(),
    88:        repo_owner: String,
    94:            repo_owner: repo_owner.to_owned(),
    ```

    to this:

    ```
    README.md:10:      cargo run -- -n <repo_name> -o <repo_owner> -t <srht_tracker_id>
    src/main.rs:16:    gh_repo_owner: String,
    src/main.rs:52:            opt.gh_repo_owner.to_owned(),
    src/main.rs:132:        .get_gh_issues(opt.gh_repo_owner, opt.gh_repo_name, Some(50))
    src/github/queries.rs:10:        pub repo_owner: String,
    src/github/queries.rs:19:        #[arguments(owner = &args.repo_owner, name = &args.repo_name)]
    src/github/queries.rs:79:        pub repo_owner: String,
    ```

    Can be done by enabling `vertico-grid-mode` but that then breaks the menu of `M-x`. Vertico should be configured through the `vertico-multiform-mode` extension, see [here](https://github.com/minad/vertico/blob/main/extensions/vertico-multiform.el) and [this blog post](https://kristofferbalintona.me/posts/202202211546/#vertico).

2. Disable the preview of selected result when editing the search query with `M-d` (`kill-word`) or `M-DEL` (`backward-kill-word`) or any other `M-` command, even if it does nothing.

What's causing this behaviour? Maybe equivalent to `M-x +vertico/embark-preview`?
    What's causing this behaviour? Maybe equivalent to `M-x +vertico/embark-preview`?

3. The "find file" does not open the file with `TAB` when there is a single occurence.

4. The lsp diagnostic buffer (`+default/diagnostics (C-c c x)`) does not gets updated.

5. When opening "Switch to buffer", paths are confusing.
    ```
    main.rs                ---  8.3k     Rustic                …cts/sr.ht/gh-migrate-issues/src/main.rs
    Cargo.toml             ---  1.2k     Conf[TOML]            …ects/sr.ht/gh-migrate-issues/Cargo.toml
    README.md              ---  2.9k     GFM                   …jects/sr.ht/gh-migrate-issues/README.md
    github.rs<2>           ---  4.4k     Rustic                …ht/gh-migrate-issues/src/http/github.rs
    sourcehut.rs           ---  3.7k     Rustic                …gh-migrate-issues/src/http/sourcehut.rs
    queries.rs<2>          ---  2.1k     Rustic                …migrate-issues/src/sourcehut/queries.rs
    ```

## other solved config issues

- FIXED newline after commented line add a new commented line (should add an empty line)

R emacs/Dockerfile.emacs-native-comp => emacs/Dockerfile +12 -20
@@ 3,6 3,8 @@ FROM debian:bookworm-slim
LABEL MAINTAINER "jman <emacs@city17.xyz>"
# reference and inspiration: https://www.masteringemacs.org/article/speed-up-emacs-libjansson-native-elisp-compilation

ENV CC="gcc-12"

# Needed for add-apt-repository, et al.
#
# If you're installing this outside Docker you may not need this.


@@ 13,13 15,11 @@ RUN apt update && apt upgrade -y \
        curl \
        gnupg-agent \
        software-properties-common \
        git
        git \
        nano

# Install generic dependencies
# with GUI
# RUN apt install -y --no-install-suggests clang autoconf make texinfo libxpm-dev libjpeg-dev libgtk-3-dev libgif-dev libtiff-dev libpng-dev libgnutls28-dev libncurses5-dev libsystemd-dev libharfbuzz-dev libgccjit-10-dev gcc-10 g++-10 libxt-dev libxml2-dev
# without GUI
RUN apt install -y build-essential clang autoconf make texinfo libgnutls28-dev libncurses5-dev libsystemd-dev libharfbuzz-dev libgccjit-11-dev gcc-11 g++-11 libxt-dev libxml2-dev
RUN apt install -y build-essential clang autoconf make texinfo libgnutls28-dev libncurses5-dev libsystemd-dev libharfbuzz-dev libgccjit-12-dev gcc-12 g++-12 libxt-dev libxml2-dev libgccjit0

# Needed for fast JSON and the configure step
# and checkinstall to build the .deb


@@ 33,26 33,18 @@ RUN rm -rf /var/lib/apt /var/lib/dpkg /var/lib/cache /var/lib/log
# do this.
ENV DEBIAN_FRONTEND=noninteractive

RUN adduser --disabled-password jman
USER jman
WORKDIR .
RUN git clone --depth=1 --single-branch git://git.savannah.gnu.org/emacs.git

RUN cd /home/jman && git clone --depth=1 git://git.savannah.gnu.org/emacs.git
# HACK: patch the Makefile to overwrite /etc/publicsuffix.gz
RUN cd emacs && sed -e 's/-9n "..\/etc\/publicsuffix.txt/-9nf "..\/etc\/publicsuffix.txt/' Makefile.in > test.in && mv test.in Makefile.in

# Configure and compile
# with GUI
# RUN cd /home/$USER/emacs && ./autogen.sh && ./configure --prefix=/home/$USER/.local --bindir=/home/$USER/.local/bin --with-native-compilation --with-xml2=yes --with-mailutils --with-gnutls=yes
# with pure GTK
# RUN cd /home/$USER/emacs && ./autogen.sh && ./configure --prefix=/home/$USER/.local --bindir=/home/$USER/.local/bin --with-native-compilation --with-xml2=yes --with-mailutils --with-gnutls=yes --with-pgtk
# without GUI
RUN cd /home/jman/emacs && ./autogen.sh && ./configure --prefix=/home/jman/.local --bindir=/home/jman/.local/bin --with-native-compilation --with-mailutils --with-xml2=yes --without-gpm --with-x=no --with-xpm=no --with-jpeg=no --with-png=no --with-gif=no --with-tiff=no --with-gnutls=yes
RUN cd emacs && ./autogen.sh && ./configure --prefix=/home/jman/.local --bindir=/home/jman/.local/bin --with-mailutils --with-xml2=yes --without-gpm --with-x=no --with-gnutls=yes --with-native-compilation --with-json --with-xpm=no --with-jpeg=no --with-png=no --with-gif=no --with-tiff=no

RUN cd /home/jman/emacs && make -j $(nproc)
# && make install-strip
RUN cd emacs && make -j $(nproc) && make install-strip

# make .deb
RUN cd /home/jman/emacs && checkinstall -y -D --pkgname=emacs-nc --pkgversion="28.0.master-0ae38ec94a" --requires="libjansson4,libharfbuzz0b,libncurses6,libgccjit0,libxml2,libgnutls30" --pkggroup=emacs --gzman=yes --install=no make install-strip

##
# NOTE: the resulting package will require ~150mb dependencies
RUN cd emacs && export commit=$(git log --format="%h" -n 1) && checkinstall -y -D --pkgname=emacs --pkgversion="28.0.50.master-$commit" --requires="libjansson4,libharfbuzz0b,libncurses6,libgccjit0,libxml2,libgnutls30" --pkggroup=emacs --gzman=yes --install=no make install-strip

CMD ["/bin/bash"]

M emacs/README.md => emacs/README.md +6 -9
@@ 28,10 28,10 @@ Also `emacs --debug-init` to debug startup errors.

## Compiling emacs

I note down also the configure script I use to build Emacs from sources. See the script `emacs-build.sh` for a step by step procedure.
Here the configure scripts for my custom Emacs builds. See the script [emacs-build.sh](./emacs-build.sh) for a step by step procedure.

```
# GUI build (with pure GTK enabled, no Xorg)
# GUI build (pure GTK, no Xorg needed, works on Wayland)
./configure --prefix=/home/$USER/.local --bindir=/home/$USER/.local/bin \
    --with-mailutils \
    --with-xml2=yes \


@@ 42,7 42,7 @@ I note down also the configure script I use to build Emacs from sources. See the
    --with-json \
    --with-pgtk

# Console only version (basically equals to running "emacs -nw")
# Console only version (no image support, basically equals to running "emacs -nw")
./configure --prefix=/home/$USER/.local --bindir=/home/$USER/.local/bin \
    --with-mailutils \
    --with-xml2=yes \


@@ 54,15 54,12 @@ I note down also the configure script I use to build Emacs from sources. See the
    --with-xpm=no --with-jpeg=no --with-png=no --with-gif=no --with-tiff=no
```

or using Docker with this [Dockerfile](Dockerfile.emacs-native-comp)
or using Docker with this [Dockerfile](./Dockerfile)

```
$ ls
emacs Dockerfile.emacs-native-comp
$ cd emacs
$ docker build -t debian:emacs-builder -f ../Dockerfile.emacs-native-comp .
$ docker build -t debian:emacs-builder .
$ container_id=$( docker run -d  --name kill-me-when-finished debian:emacs-builder )
$ docker cp $container_id:/src/emacs-nc_0.1-1_amd64.deb .
$ docker cp $container_id:/emacs/emacs-my-custom-build.deb .
$ docker rm kill-me-when-finished
```