Skip to content

Instantly share code, notes, and snippets.

@sogaiu
sogaiu / issue-3-comment.md
Last active May 13, 2026 07:33
janet-ts-mode custom indentation

The latest approach is to try to get different behavior based on whether the indentation is line-related or region-related.

Emacs provides two variables that can be set to functions that handle each type of indentation:

  • indent-region-function, and
  • indent-line-function

The idea is to provide an appropriate function for each of these variables.

I've tried out the code below along with the following commands:

# https://github.com/sogaiu/jog
$ jog '{:dump true}' ~/src/janet/src/boot/boot.janet
[
["/home/user/src/janet/src/boot/boot.janet" 11 3 "def" "defn" nil "```\n (defn name & more)\n\n Define a function. Equivalent to `(def name (fn name [args] ...))`.\n ```"]
["/home/user/src/janet/src/boot/boot.janet" 47 3 "defn" "defmacro" "[name & more]" "\"Define a macro.\""]
["/home/user/src/janet/src/boot/boot.janet" 52 3 "defmacro" "as-macro" "[f & args]" "``Use a function or macro literal `f` as a macro. This lets\n any function be used as a macro. Inside a quasiquote, the\n idiom `(as-macro ,my-custom-macro arg1 arg2...)` can be used\n to avoid unwanted variable capture of `my-custom-macro`.``"]
["/home/user/src/janet/src/boot/boot.janet" 60 3 "defmacro" "defmacro-" "[name & more]" "\"Define a private macro that will not be exported.\""]
["/home/user/src/janet/src/boot/boot.janet" 65 3 "defmacro" "defn-" "[name & more]" "\"Define a private function that will not be exported.\""]
["/home/user/src/janet/src/boot/
@sogaiu
sogaiu / doc-string.janet
Created May 12, 2026 08:35
remarkable trees
(import ../src/remarkable/remarkable :as r)
(comment
# paragraphs
(def paragraphs
``
This is the first paragraph.
This is another paragraph.

mikethompson:

I've found the AIs to be amazing. Staggering really. But I do regard them like a 12 year old savant.  Most problems come from them not having enough information. There's stuff in your head that they don't know.

Hence being spec driven. I have to iterate before I ask them to do anything substantive.

Spec driven just means "prompt engineering driven"

The imperative code that didibus found was because I never said "prefer a functional solution unless it impacts performance critical code". The moment I did, we were good.

@sogaiu
sogaiu / gud-auto-center-source-buffer.el
Created April 25, 2026 23:36
emacs gdb auto-center source buffer around current line
;; references:
;;
;; * https://superuser.com/a/118138
;; * https://superuser.com/a/1680006
;; * http://kousik.blogspot.com/2005/10/highlight-current-line-in-gdbemacs.html
(defadvice gud-display-line (after my-gud-display-line-center activate)
;; true-file is an argument to the original function
(let* ((buffer (gud-find-file true-file)))
(save-excursion
(with-selected-window (get-buffer-window buffer)
@sogaiu
sogaiu / notes.md
Created April 25, 2026 04:03
janet near far regalloc
JanetSlot janetc_value(JanetFopts opts, Janet x) {
    JanetSlot ret;
    JanetCompiler *c = opts.compiler;
    // ...
    /* Special forms */
    if (spec) {
        const Janet *tup = janet_unwrap_tuple(x);
        ret = spec->compile(opts, janet_tuple_length(tup) - 1, tup + 1);
@sogaiu
sogaiu / gist:ca62b9d09d810a1ae3a8ddcc701caccc
Last active April 21, 2026 10:26
emacs and tree-sitter compatibility(?) issue
* compiling emacs 30.2 with too recent of a tree-sitter version (0.26.x?) may cause issues with existing
queries.
* https://gitlab.archlinux.org/archlinux/packaging/packages/emacs/-/work_items/13
* https://github.com/emacs-mirror/emacs/commit/b01435306a36e4e75671fbe7bacea351f89947d5
Number Opcode Name Signature Arity Type Bytes Description
0 JOP_NOOP noop (noop) 0 JINT_0 Does nothing.
1 JOP_ERROR err (err message) 1 JINT_S A Throw error $message.
2 JOP_TYPECHECK tchck (tchck slot types) 2 JINT_ST A:E Assert $slot matches types
3 JOP_RETURN ret (ret val) 1 JINT_S D:A Return $val
4 JOP_RETURN_NIL retn (retn) 0 JINT_0 A Return nil
5 JOP_ADD_IMMEDIATE addim (addim dest lhs im) 3 JINT_SSI B:CS:A $dest = $lhs + im
6 JOP_ADD add (add dest lhs rhs) 3 JINT_SSS B:C:A $dest = $lhs + $rhs
7 JOP_SUBTRACT_IMMEDIATE subim (subim dest lhs im) 3 JINT_SSI B:CS:A $dest = $lhs - im
8 JOP_SUBTRACT sub (sub dest lhs rhs) 3 JINT_SSS B:C:A $dest = $lhs - $rhs
@sogaiu
sogaiu / clojure-ts-mode-extras.el
Last active April 7, 2026 15:01
"some option to infer the closing parentheses before it gets passed to whatever tree representation this mode is operating on"
;; from: https://github.com/clojure-emacs/clojure-ts-mode/issues/134#issuecomment-4178337890
;; by: https://github.com/sstraust
;; the thought is to temporarily insert the parens just before sending to
;; treesitter, and then remove them so they don't impact the user's working
;; buffer
(defun treesitter-parens--compute-closing-chars ()
(save-excursion
(save-restriction