Created
June 12, 2025 22:35
-
-
Save jwiegley/e9ef6e3302ac8b7fb93065131cfef2a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*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)) | |
(let* ((line (buffer-substring (point-at-bol) (point-at-eol))) | |
(fields (split-string line "," nil))) | |
(when (and (>= (length fields) 2) ; Ensure DRAFT exists | |
(string-match-p "^\\s-*$" (nth 1 fields))) | |
(setf (nth 1 fields) "8000") | |
(let ((new-line (mapconcat 'identity fields ","))) | |
(delete-region (point-at-bol) (point-at-eol)) | |
(insert new-line)))) | |
(forward-line 1))) | |
#+end_src | |
*Usage*: | |
1. Open the =models.csv= buffer. | |
2. Evaluate this code (e.g., with =M-x eval-buffer=). | |
3. Run =M-x set-draft-column= to process the buffer. | |
This code: | |
- Skips the header row. | |
- For each line, splits fields by commas (=","=) without omitting empty entries. | |
- Checks if the second column (DRAFT) is empty. | |
- Replaces it with =8000= and reconstructs the line. | |
*Note*: This strictly follows your request to target the /second column/. If you meant the /third column (NUM_CTX)/ instead, adjust =(nth 1 fields)= to =(nth 2 fields)=. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment