Just learned that using [[Emacs]], press C-\ to set input method to TeX, then input Greek symbols will be very easy, for example type \theta will display θ
Here are some frequently used symbols when writing math equations.
In macOS, I’ve configured a variety of shortcuts to automate tasks, for example:
Appending selected text to a specified Obsidian note.
Opening a prompt menu and sharing the selected text with ChatGPT to obtain results.
Extracting text from an image to read in an editor.
And many others.
I frequently use these actions on both my iPhone and Mac. However, on macOS, I find myself having to manually navigate through the Services menu to activate these actions, which tends to slow down my workflow.
To streamline this process, I’ve developed a script that automatically triggers a Services menu item whenever I select text and press Command + Right Click. This enhancement significantly speeds up my interaction with macOS, making my workflow more efficient.
[[Hammerspoon]] script
-- Ensure the listener is global to avoid garbage collection issuesMouseListener=hs.eventtap.new({hs.eventtap.event.types.rightMouseDown},function(e)localbuttonPressed=e:getProperty(hs.eventtap.event.properties.mouseEventButtonNumber)localcmdPressed=e:getFlags().cmdifcmdPressed==truethen-- AppleScript to open the Services menu-- https://stackoverflow.com/a/59330902/22903883hs.osascript.applescript([[
tell application "System Events"
set appName to item 1 of (get name of processes whose frontmost is true)
tell (process 1 where frontmost is true)
tell menu bar 1
tell menu bar item appName
tell menu appName
tell menu item "Services"
tell menu "Services"
click menu item "GPT: Share"
end tell
end tell
end tell
end tell
end tell
end tell
end tell]])returntrue-- Consume the right-right-clickendreturnfalseend)-- Start the event listenerMouseListener:start()
Using lsp-bridge for Language Server Protocol in Emacs
Emacs 29 introduced built-in TRAMP Docker support for editing files within containers. However, enabling auto-completion inside a container remains challenging.
After discovering
lsp-bridge
, I realized the benefit of a Python process interacting with the language server, rather than relying solely on Emacs Lisp.
I added a feature for automatic reconnection to remote SSH servers and started supporting devcontainers. Using nix-darwin to configure my MacBook, I implemented the
devcontainer feature
to install lsp-bridge and the language server within the devcontainer. This was facilitated by the
Nix ecosystem
. To make it work, I needed to start with patching the official Nix devcontainer feature and create separate projects — a long journey, but worthwhile.
Container File Buffer Handling
When opening files in a container, lsp-bridge creates an lsp-bridge buffer, inserts the file content, and uses it for editing and rendering diagnostic information. The remote file content on the container is maintained by the lsp-bridge server running inside the container.
I completed the handling of the visited file modification time for the buffer and enabled auto-revert mode to reload file content automatically when the formatter updates the file.
Using the created lsp-bridge buffer, I used set-visited-file-name to associate a buffer with a file path. However, saving the buffer after the first save prompts a warning: “File has been changed since visited.” This occurs due to discrepancies in how file timestamps are handled by Emacs through TRAMP. To resolve this, Emacs’ record of the file’s modification time must be manually updated with something like this:
Emacs’ “auto-revert” mode, which automatically reverts buffers when the displayed files change externally, is also useful when files are updated by the formatter. Therefore, the file buffer must enable auto-revert-mode.
With these pieces in place, I now have a smooth editing experience with auto-completion inside the devcontainer.
When taking notes, friction is often a good thing. If it is too easy to create a new note, you don’t write something on your own, but rather just collect information. Consequently, your brain do not process the information, so you learn less from just collecting and reading it. Physical notes have a physical constraint and a limitation on how much we can write on them, but digital notes have no such limitation and rely on self-discipline. So, when taking notes, it is too easy to write too many words. Keep it short and simple.
I use
vertico-postframe
to place my completion window at the center of screen, however when doing incremental search like doom-emacs SPC s s, it will block the man window.
Here is how to temporarily disable vertico-posframe-mode in Emacs before executing a function, like an incremental search, and then re-enable it afterward.
(defunmy-search-without-posframe()"Perform a search without `vertico-posframe-mode' temporarily."(interactive);; Disable vertico-posframe-mode if it's enabled(when(bound-and-true-pvertico-posframe-mode)(vertico-posframe-mode-1)(unwind-protect;; Perform the search(call-interactively'+default/search-buffer);; Re-enable vertico-posframe-mode(vertico-posframe-mode1))))
in config.el
(map!:leader:desc"Search without posframe""s s"#'my-search-without-posframe)
modify only the height of headings in Org mode without affecting other attributes like color
Instead of using custom-theme-set-faces which replaces the whole face definition (and could unintentionally override theme-specific settings like color), use set-face-attribute
doom-emacs config example
(after!org;; Adjust the height of org headings upon org-mode startup(add-hook'org-mode-hook(lambda()(dolist(face'((org-level-1.1.75)(org-level-2.1.5)(org-level-3.1.25)(org-level-4.1.1)(org-level-5.1.05)(org-level-6.1.0)(org-level-7.0.95)(org-level-8.0.9)))(set-face-attribute(carface)nil:height(cdrface)))))
Posting a markdown document directly to Telegram will display formatting like code blocks and bold text in the message. However, the content received by the Telegram bot differs from what is initially sent, particularly with the removal of backticks.
To send the message content as plain text without formatting, I first paste it into Apple Note on iOS and then share it with the Telegram bot.
Lexical Binding: Before Emacs 24 emacs-lisp is dynamic binding. lexical binding is introduced in Emacs 24, enabling compile-time optimizations.
Native Compilation: Introduced in Emacs 28, native compilation used the GCC JIT compile to convert Emacs Lisp code to native machine code, dramatically improving execution speed.
Package Management
Lazy loading with use-package: use-package is now build into Emacs 29
Straight Package Manager
: works with use-package to handle package installations and version control.
Syntax Highlighting and Parsing
Tree-sitter Integration: Emacs 29 includes support for Tree-sitter, a parser generator that improves syntax highlighting and code navigation by using precise parse trees instead of regular expressions. This results in more accurate and faster syntax highlighting.
tree-sitter mode: new major modes that utilize tree-sitter for enhanced code parsing and highlighting, for example, use python-ts-mode to replace traditional python-mode.
Completion Frameworks
Historical Context: Initially, Emacs used ido for interactive file and buffer navigation, followed by heavier frameworks like helm and ivy for more advanced completions.
Modern Solutions: verticoconsultorderlessmarginaliaembark
Language Server Protocol (LSP)
eglot: Emacs’ build-in LSP client
I personally use
lsp-bridge
for completion and LSP
config-sketchybar is a local git submodule, we can define a package using it as source.
pkg-sketchybar-config.nix
{inputs,pkgs,...}:pkgs.stdenv.mkDerivation{name="sketchybar-config";dontConfigure=true;dontUnpack=true;src=inputs.config-sketchybar-src;installPhase=''
mkdir -p $out
cp -r $src/config/sketchybar/* $out
# Find all .sh files and substitute 'jq' with the full path to the jq binary
find $out -type f -name "*.sh" | while read script; do
substituteInPlace "$script" \
--replace 'jq' '${pkgs.jq}/bin/jq'
done
chmod -R +x $out
'';}
and pkg-sketchybar-config can be included in home.nix as regular package.