Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handling of d2-flags #48

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions d2-mode.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;; d2-mode.el --- Major mode for working with d2 graphs -*- lexical-binding: t; -*-

Check failure on line 1 in d2-mode.el

View workflow job for this annotation

GitHub Actions / build (windows-latest, snapshot)

package.el cannot parse this buffer: Can't read whole string

;; Author: Andor Kesselman <[email protected]>
;; Copyright (C) 2022, Andor Kesselman
Expand Down Expand Up @@ -84,10 +84,10 @@
:group 'd2
:type 'string)

(defcustom d2-flags ""
(defcustom d2-flags nil
"Additional flags to pass to the d2-cli."
:group 'd2
:type 'string)
:type '(repeat string))

(defconst d2-font-lock-keywords
`((,(regexp-opt '("shape" "md" ) 'words) . font-lock-keyword-face)
Expand All @@ -114,10 +114,12 @@
(let* ((out-file (or (cdr (assoc :file params))
(error "D2 requires a \":file\" header argument")))
(temp-file (org-babel-temp-file "d2-"))
(cmd (concat (shell-quote-argument d2-location)
" " temp-file
" " (org-babel-process-file-name out-file)
" " d2-flags)))
(cmd (mapconcat #'shell-quote-argument
(append (list d2-location
temp-file
(org-babel-process-file-name out-file))
d2-flags)
" ")))
(with-temp-file temp-file (insert body))
(org-babel-eval cmd "")
nil))
Expand Down Expand Up @@ -163,10 +165,10 @@
(interactive "fFilename: ")
(let* ((input file-name)
(output (concat (file-name-sans-extension input) d2-output-format)))
(apply #'call-process d2-location nil "*d2*" nil (list input output))
(apply #'call-process (shell-quote-argument d2-location) nil "*d2*" nil (append (list input output) d2-flags))
(if (equal browse t)
(progn
(d2-browse-file output))
(progn
(d2-browse-file output))
(progn
(display-buffer (find-file-noselect output t))))))

Copy link
Owner

@andorsk andorsk Jun 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the following:

Suggested change
;;;###autoload
(defsubst string-join (strings &optional separator)
"Join all STRINGS using SEPARATOR.
Optional argument SEPARATOR must be a string, a vector, or a list of
characters; nil stands for the empty string."
(declare (pure t) (side-effect-free t))
(mapconcat #'identity strings separator))

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: tested this and it seemed to work. Let's get this in and merge to main. After #47 , bump version.

Copy link
Contributor Author

@terlar terlar Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went for mapconcat directly instead, since then I can specify the separator and can also apply the shell-quote-argument to all arguments which is good practice.

Expand Down
Loading