Skip to content

Commit

Permalink
improve JsonAsPlist mold to handle regions
Browse files Browse the repository at this point in the history
  • Loading branch information
ag91 committed Feb 22, 2024
1 parent 8ff5daa commit e889ae6
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions molds/core.el
Original file line number Diff line number Diff line change
Expand Up @@ -526,19 +526,26 @@ It specializes for source code."

(me-register-mold
:key "JsonAsPlist"
:given (:fn (eq major-mode 'json-mode)) ;; TODO or region contains json
:let ((json
(ignore-errors
(let ((region (if (region-active-p)
(substring-no-properties (funcall region-extract-function))
(buffer-string))) ;; TODO not sure if this is a good idea performance-wise
(json-object-type 'plist)
(json-array-type 'list))
(with-temp-buffer
(insert region)
(goto-char (point-min))
(json-read))
))))
:given (:fn (and
json))
:then (:fn
(let ((json
(save-excursion
(let ((json-object-type 'plist)
(json-array-type 'list))
(goto-char (point-min))
(json-read)))))
(with-current-buffer buffername
(erase-buffer)
(emacs-lisp-mode)
(me-print-to-buffer json)
(setq-local self json)))))
(with-current-buffer buffername
(erase-buffer)
(emacs-lisp-mode)
(me-print-to-buffer json)
(setq-local self json))))

(me-register-mold
:key "PlistToJson"
Expand Down

0 comments on commit e889ae6

Please sign in to comment.