Skip to content

Instantly share code, notes, and snippets.

View jwiegley's full-sized avatar

John Wiegley jwiegley

View GitHub Profile
*Prompt*: Emacs lisp code to sort the first column alphabetically, and delete all columns containing "N/A" in buffer "test.csv". /no_think
*Response*:
Here's an Emacs Lisp script to:
1. Open the buffer =test.csv=.
2. Sort the buffer alphabetically by the *first column*.
3. Delete all rows where *any column contains "N/A"*.
#+begin_src elisp
*Response*:
Here's the Emacs Lisp code to set the *second column (DRAFT)* to =8000= for rows where it's empty:
#+begin_src emacs-lisp
(defun set-draft-column ()
"Set empty DRAFT column to 8000 in current CSV buffer."
(interactive)
(goto-char (point-min))
(forward-line 1) ; Skip header
(while (not (eobp))
(use-package gptel-commit
:no-require t
:after (gptel git-commit)
:preface
(defun my/gptel-commit-summary ()
"Insert a commit message header line in the format I use, followed by a
standard magit (GNU style) changelog.
Don't get the LLM to write the commit message itself, because it's bad
at inferring my intent.
warning: 'show-derivation' is a deprecated alias for 'derivation show'
{
"/nix/store/8y906wkzzx91i4948y4f9x8vs8c6wpxy-libarchive-3.7.8.drv": {
"args": [
"-e",
"/nix/store/vj1c3wf9c11a0qs6p3ymfvrnsdgsdcbq-source-stdenv.sh",
"/nix/store/shkw4qm9qcw5sc5n1k5jznc83ny02r39-default-builder.sh"
],
"builder": "/nix/store/p8972c250zr90fph2sgxr71m3ic45xck-bash-5.2p37/bin/bash",
"env": {
(defun synchronous (func)
"Make any asynchronous function into a synchronous one.
FUNC is called with a callback to be called when the asynchronous
function is finished. For example, in the case where make-thread
is used to run a function asynchronously, which when complete,
finishes the synchronous call.
(synchronous
#'(lambda (k)
(make-thread #'(lambda ()
(defun eshell/gptel (&rest args)
(eshell-eval-using-options
"gptel" args
'((?h "help" nil nil "show this usage screen")
(?n "dry-run" nil dry-run "Only show what would happen")
(?m "model" nil model "LLM model to use")
(?s "system" nil system "System prompt to use (optional, can be a symbol)")
(?S "stream" nil stream "Whether to stream the output")
:usage "[OPTION...] [PROMPT]
Send prompt (or context, or both) to an LLM.")
(cl-defstruct (eshell-function-target
(:constructor nil)
(:constructor eshell-function-target-create
(output-function &optional close-function)))
"An Eshell target that calls an OUTPUT-FUNCTION."
output-function close-function)
(defun eshell-exec-lisp (printer errprint func-or-form args form-p)
"Execute a Lisp FUNC-OR-FORM, maybe passing ARGS.
PRINTER and ERRPRINT are functions to use for printing regular
(defun eshell-exec-lisp (printer errprint func-or-form args form-p)
"Execute a Lisp FUNC-OR-FORM, maybe passing ARGS.
PRINTER and ERRPRINT are functions to use for printing regular
messages and errors, respectively. FORM-P should be non-nil if
FUNC-OR-FORM represent a Lisp form; ARGS will be ignored in that
case."
(eshell-condition-case err
(let ((result
(save-current-buffer
(if form-p
(defun eshell-lisp-command (object &optional args)
"Insert Lisp OBJECT, using ARGS if a function."
(unless eshell-allow-commands
(signal 'eshell-commands-forbidden '(lisp)))
(catch 'eshell-external ; deferred to an external command
(when (memq eshell-in-pipeline-p '(nil last))
(eshell-set-exit-info 0))
(setq eshell-last-arguments args)
(let* ((eshell-ensure-newline-p t)
(command-form-p (functionp object))
(defun eshell-exec-lisp (printer errprint func-or-form args form-p)
"Execute a Lisp FUNC-OR-FORM, maybe passing ARGS.
PRINTER and ERRPRINT are functions to use for printing regular
messages and errors, respectively. FORM-P should be non-nil if
FUNC-OR-FORM represent a Lisp form; ARGS will be ignored in that
case."
(eshell-condition-case err
(let ((result
(save-current-buffer
(if form-p