Emacs consult-buffer filenames #

When working on my web projects I often have same the same filename in different folders, such as projectname/index.html and anotherproject/index.html.

When opening files in Emacs, I might have to open index.html if I'm already in projectname/ or type ../anotherproject/index.html to open from another folder. I switch folders enough that I wanted to have a more consistent way to open things. I now use a global find-file that lets me match on the complete pathname. I can open projectname/index from anywhere, without having to type something different based on which folder I'm in.

When switching buffers, either with the built-in function or with consult-buffer from consult.el, I can type index.html if I only have one index.html file open. If I have more than one open, Emacs will rename them index.html<projectname>, index.html<anotherproject>, etc., and then I would type index projectname. But if I have only one open, then typing index projectname will fail. I wanted to make it more consistent so that I could always type index projectname whether there's only one index.html buffer open or multiple. I implemented this by putting the full filename instead of the buffer name into consult's buffer list:

Labels:

Observational studies #

Star Trek Red Shirt
Star Trek Red Shirt,
Wikipedia, Derek Springer, CC BY-SA 2.0

People who wear red shirts on the original Star Trek have a high mortality rate.

  1. can we conclude that red shirts caused the high mortality rate?
  2. can we solve the problem by having them yellow shirts instead?

Labels:

Status codes like TODO #

I often put TODO comments into my projects, including in source code. And I'll change it to DONE afterwards. I ended up keeping a list of four-letter codes:

Diagram showing how my status codes are related to each other, e.g. TODO happens before DONE

Labels:

Using an LLM to query my notes #

robot asks a question holding a book
"robot asks a question holding a book" image from stable diffusion

I occasionally play with LLMs (large language models). Last time I had tried Simon Willison's llm software to search over my notes. Today I tried amaiya/onprem to ask questions about my notes. The documentation is pretty good but I made a few changes for my configuration, so I decided to write them down here. I'm running these on my Mac M1 and not on my Linux or Windows machines.

First step, get the thing installed:

cd ~/Projects/machine-learning/
mkdir onprem
cd onprem

# need to use python 3.9 through 3.11 for torch support; 3.12 doesn't support it yet
# check the version I have installed
python3 --version
# if python3 isn't a reasonable version, then install or choose a different python
# before doing the next step

python3.11 -m venv venv
source venv/bin/activate

# install onprem itself, which also installs torch
pip install onprem
mkdir data

Labels:

Emacs and shellcheck #

Julia Evans had a great talk called Making Hard Things Easy. One of the takeaways for me was that I should be using tools for parts of a system I find hard to remember. In particular, when writing bash scripts I should be using shellcheck.

It turns out Emacs 29 has support for shellcheck, and older versions of Emacs can use the flymake-shellcheck page.

To set it up in Emacs 29:

(use-package flymake
  :bind (("H-e" . flymake-show-project-diagnostics)))

(use-package sh-script
  :hook (sh-mode . flymake-mode))

I use consult for navigating my errors, and I want to make errors more noticable in the mode line, so my flymake configuration is:

(use-package flymake
  :bind (("H-e" . my/consult-flymake-project))
  :preface
  (defun my/consult-flymake-project ()
    (interactive)
    (consult-flymake t))
  :custom
  (flymake-suppress-zero-counters t)
  :config
  (defface my/flymake-modeline-error-echo
    '((t :inherit 'flymake-error-echo :background "red"))
    "Mode line flymake errors")
  (put 'flymake-error 'mode-line-face 'my/flymake-modeline-error-echo)
  (defface my/flymake-modeline-warning-echo
    '((t :inherit 'flymake-warning-echo :background "orange"))
    "Mode line flymake warnings")
  (put 'flymake-warning 'mode-line-face 'my/flymake-modeline-warning-echo))

It's too early to know what other tweaks I might want, but so far it's alerted me to several errors in my shell scripts.

Update: [2023-10-07] Comments on HN pointed to bash-language-server which works with emacs lsp or eglot.

Labels: