somegrass31 · 2022-12-06 21:35
codemuncher · 2022-12-07 05:37
oh fantastic usage!
KuangPoulp · 2022-12-07 09:26
What's the website?
somegrass31 · 2022-12-07 09:41
https://chat.openai.com/chat
somegrass31 · 2022-12-07 10:06
It's absolutely fantastic. It can also generate pure elisp code as well. It could be super useful for people that are new to elisp and want to add something relatively complicated to their config.
sunnyata · 2022-12-07 12:43
But they wouldn't be able to tell whether the code was incorrect or work out what was wrong with it. It's amazingly clever but it is quite often confidently wrong.
centzon400 · 2022-12-07 13:21
My prompt was:
"Generate an emacs lisp function that converts a region of YAML frontmatter to Org Mode front matter"
I don't know what to say. It works. No edge cases and a bit "wordy", but it works.
(defun convert-markdown-yaml-to-org-front-matter ()
"Convert a region of Markdown front matter in YAML format to org mode front matter.
If no region is active, the function converts the front matter of the
current buffer. The front matter is assumed to start at the beginning
of the buffer or the first line of the region, and end at the first
blank line or the end of the region.
The function replaces the original front matter with the converted
version, leaving the rest of the buffer unchanged. The converted
front matter is indented by one space."
(interactive)
(save-excursion
(let ((start (if (use-region-p) (region-beginning) (point-min)))
(end (if (use-region-p) (region-end) (point-min))))
(goto-char start)
(unless (bolp) (forward-line))
(setq start (point))
(goto-char end)
(skip-chars-backward " \t\n")
(forward-line)
(setq end (point))
(let ((front-matter (buffer-substring start end)))
(delete-region start end)
(insert (convert-markdown-yaml-front-matter-to-org front-matter))))))
(defun convert-markdown-yaml-front-matter-to-org (markdown-front-matter)
"Convert MARKDOWN-FRONT-MATTER, a string containing Markdown
front matter in YAML format, to org mode front matter.
The function returns the converted front matter as a string. It
does not handle multi-line values or nested objects."
(with-temp-buffer
(insert markdown-front-matter)
(goto-char (point-min))
(while (re-search-forward "^\\([^:]+\\):\\(.*\\)$" nil t)
(replace-match ":#+\\1 \\2"))
(buffer-string)))
peterhoeg · 2022-12-07 13:55
Also notice how the comment and the code are not aligned. Without a region it first of all does point-min to point-min, which is obviously wrong. But if it does min to max instead it doesn't match the comment which says "until a blank line".