Skip to content

Commit

Permalink
add chatu-inline
Browse files Browse the repository at this point in the history
  • Loading branch information
kimim committed Feb 28, 2024
1 parent bd566ef commit 31b927b
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
54 changes: 54 additions & 0 deletions chatu-inline.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
;;; chatu-inline.el --- Chatu for inline code -*- lexical-binding: t -*-

;; Copyright (c) 2024 Kimi Ma <[email protected]>

;; Author: Kimi Ma <[email protected]>
;; URL: https://github.com/kimim/chatu
;; Keywords: multimedia convenience

;; This file is NOT part of GNU Emacs.

;;; License:

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; script and open function for inline script

;;; Code:

(require 'chatu-common)

(defun chatu-inline-script (keyword-plist)
"Open input.
KEYWORD-PLIST contains parameters from the chatu line."
(let* ((input (plist-get keyword-plist :input-path))
(output (plist-get keyword-plist :output-path))
(script (plist-get keyword-plist :script)))
(string-replace
"%o" (shell-quote-argument output)
(string-replace
"%i" (shell-quote-argument input) script))))

(defun chatu-inline-open (keyword-plist)
"Open input file.
KEYWORD-PLIST contains parameters from the chatu line."
(interactive)
(let* ((path (plist-get keyword-plist :input-path)))
(chatu-common-open-other-window path "")))

(provide 'chatu-inline)

;;; chatu-inline.el ends here
10 changes: 9 additions & 1 deletion chatu.el
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@
(substring-no-properties
(match-string 1 line)))))

(defun chatu-get-script (line)
"Get chatu inline script from string LINE."
(when (string-match ":script +\"\\(.*\\)\"[ \\t\\n]*" line)
(list :script
(substring-no-properties
(match-string 1 line)))))

(defvar chatu-keyword-value-functions
'(chatu-get-keyword
chatu-get-settings
Expand All @@ -195,7 +202,8 @@
chatu-get-output
chatu-get-page
chatu-get-input-dir
chatu-get-output-dir))
chatu-get-output-dir
chatu-get-script))

(defun chatu-normalize-keyword-plist (keyword-plist)
"Normalize KEYWORD-PLIST."
Expand Down
4 changes: 4 additions & 0 deletions docs/chatu.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@
# LilyPond
<!-- #+chatu: :lilypond "joy" -->
![](./images/joy.svg)

# inline script
<!-- #+chatu: :inline "inline.jpg" :output "inline.jpg" :script "convert %i -negate %o" -->
![](./images/inline.jpg)
7 changes: 7 additions & 0 deletions docs/chatu.org
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ Even more specific about input-dir, output-dir and output file name:
#+chatu: :lilypond "joy"
#+results:
[[file:./images/joy.svg]]

* inline shell script
:PROPERTIES:
:ORDERED: t
:END:
#+chatu: :inline "inline.jpg" :output "inline.jpg" :script "convert %i -negate %o"
[[file:./images/inline.jpg]]
Binary file added docs/draws/inline.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/inline.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 31b927b

Please sign in to comment.