Skip to content

Commit

Permalink
Don't use regexp
Browse files Browse the repository at this point in the history
Although immediate motivation is byte compiler error in older Emacs
due to rx not supporting "literal" clause, it is also the case that we
need not use a regexp at all.
  • Loading branch information
greghendershott committed Feb 12, 2024
1 parent 3dc7d92 commit 1a87321
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions racket-hash-lang.el
Expand Up @@ -403,17 +403,18 @@ Otherwise things like `racket-xp-mode' will report errors.
IFF we add one, arrange for a write-back function to remove it.
Note: `org-src--contents-for-write-back' strips text properties
so we can't insert a propertized string to look for later."
(save-excursion
(goto-char (point-min))
(unless (looking-at-p (rx bol "#lang" (1+ " ") (literal lang-str) "\n"))
(let ((lang-line-str (concat "#lang " lang-str "\n")))
(insert lang-line-str)
(setq org-src--allow-write-back
(lambda ()
(save-excursion
(goto-char (point-min))
(when (looking-at-p (rx bol (literal lang-line-str)))
(delete-region (point-min) (1+ (length lang-line-str)))))))))))
(let* ((lang-line-str (concat "#lang " lang-str "\n"))
(end-pos (1+ (length lang-line-str))))
(unless (string= (buffer-substring-no-properties (point-min) end-pos)
lang-line-str)
(save-excursion
(goto-char (point-min))
(insert lang-line-str))
(setq org-src--allow-write-back
(lambda ()
(when (string= (buffer-substring-no-properties (point-min) end-pos)
lang-line-str)
(delete-region (point-min) end-pos)))))))

(defun racket--hash-lang-org-babel-execute (lang-str body params)
"A basic way to run Racket programs using any #lang.
Expand Down

0 comments on commit 1a87321

Please sign in to comment.