From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id AFA6AnE9B2aqfAAA62LTzQ:P1 (envelope-from ) for ; Fri, 29 Mar 2024 23:15:13 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id AFA6AnE9B2aqfAAA62LTzQ (envelope-from ) for ; Fri, 29 Mar 2024 23:15:13 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1711750513; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=omIOJi+GgUj9YG61TLFz5yaR85+HXbkrqN05JwrXiww=; b=AGilmqPMqbQDKZuWvVHKZwVxrJxQiPf7inkDb9W12i2lGcOPJc0JTCnsEjKZe0mRwiVJft QwRHFCnmJtVjRokESEov5yQkm+d9SUDk5wlCpWqEfph/vj0Xq6KBXP09ZKKFQxfWOqDX00 EYcKbJs18uZcTkqjanzBACNj8z1Qr6n3OT0+VL1M36d29vYsbJagwOCUZAXKVAd57LyxgI lldEDFvHOyfZTOorLXbRU+hd5pucSMvEPFeQo5oriSgLOO0/9GdmujR8Ohd12BUvhSv/Lw CKHpclSV24zrPhOqpMMBMNh/YvZkUTWxrUKllqEBnxP+IPVi+1DF7wg4b/MsfA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1711750513; a=rsa-sha256; cv=none; b=UbSWhpNFkCj0PtpyocdXOzNziplnQ46uJsmSUzdiS3ArwQsYkIa6G4lnlxhEQFCHev3h+E dzuy4KraKWrV98BkOXT4/VLXtw2VfXq2XViAiaJtlv2RF+I+ZRxWNHXytAze1QOCUsHW9o FjzUn1fO6dLhocnr5oAeQb5tbREzR3Z1+X0twQfH7s5RHOZ/kFPWPK3AzuyyVjnCe5WAJA piznv99UNzVUR7/kYN09VK2rnWZHESu01JciNm73nOU5MrCHU7v9CFF10UxM9RePIRAjHE vFCEduBatBl9/Wb2L7fF9MHUeT8PyoK10PX1zflqDgEMnC1Tdwl+RAPNcdUlmQ== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id CD765612D for ; Fri, 29 Mar 2024 23:15:12 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rqKUH-0003OC-8b; Fri, 29 Mar 2024 18:14:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rqKUF-0003O3-Qx for emacs-orgmode@gnu.org; Fri, 29 Mar 2024 18:14:11 -0400 Received: from srv01.robewald.de ([116.203.116.97]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rqKUD-00088Z-Vd for emacs-orgmode@gnu.org; Fri, 29 Mar 2024 18:14:11 -0400 Received: from smtpclient.apple (unknown [IPv6:2a01:799:226:9e00:890e:f910:14a6:65e6]) by srv01.robewald.de (Postfix) with ESMTPSA id 01C041F547 for ; Fri, 29 Mar 2024 23:14:03 +0100 (CET) From: Robert Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.3\)) Subject: SVG Previews for org mode Message-Id: Date: Fri, 29 Mar 2024 23:14:03 +0100 To: emacs-orgmode@gnu.org X-Mailer: Apple Mail (2.3696.120.41.1.3) Received-SPF: pass client-ip=116.203.116.97; envelope-from=robert+orgmode@robewald.de; helo=srv01.robewald.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: CD765612D X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -2.93 X-Spam-Score: -2.93 X-TUID: y7EXSzJtee27 Hello, I created the attached code to be able to preview SVG in org mode. = Please comment if you have suggestions for a better approach. It works by having svg in a #+begin_src svg block and running = org-format-svg on it. I took inspiration from org-format-latex and wonder whether it should be = merged with that function. Upsides: - The same keybinding (C-c C-x C-l) could be used. - Less duplicated code - More? Downsides:=20 - The name of the function would be misleading - Other breakage - More? It could also be integrated with the C-c mechanisms on src_blocks. But I = don=E2=80=99t know how to do that. Best regards Robert (defun org--make-svg-preview-overlay (beg end image) "Build an overlay between BEG and END using the svg image data." (let ((ov (make-overlay beg end))) (overlay-put ov 'org-overlay-type 'org-svg-overlay) (overlay-put ov 'evaporate t) (overlay-put ov 'modification-hooks (list (lambda (o _flag _beg _end &optional _l) (delete-overlay o)))) (overlay-put ov 'display (find-image `((:type svg :data ,image :scale 1 = :transform-smoothing t)))))) (defun org-format-svg (&optional beg end) (let ((context-regexp "#\\+begin_src +svg")) (goto-char (or beg (point-min))) (while (re-search-forward context-regexp end t) (let* ((context (org-element-context)) (type (org-element-type context))) (when (and (eq type 'src-block)=20 (string=3D (org-element-property :language context) = "svg")) (let* ((value (org-element-property :value context)) (beg (org-element-property :begin context)) (end (save-excursion (goto-char (org-element-property :end context)) (skip-chars-backward " \r\t\n") (point)))) (progn (dolist (o (overlays-in beg end)) (when (eq (overlay-get o 'org-overlay-type) = 'org-svg-overlay) (delete-overlay o)))) (org--make-svg-preview-overlay beg end value) (goto-char end))))))) (defun org-clear-svg-preview (&optional beg end) (let ((overlays (cl-remove-if-not (lambda (o) (eq (overlay-get o 'org-overlay-type) = 'org-svg-overlay)) (overlays-in (or beg (point-min)) (or end = (point-max)))))) (mapc #'delete-overlay overlays) overlays)) (defun org-svg-preview (&optional arg) "Toggle the preview of the svg fragment at point" (interactive) (cond ((not (display-graphic-p)) nil) ;; noop on non-graphic displays ((use-region-p) (org-format-svg (region-beginning) (region-end))) ((let ((context (org-element-context))) (and (eq (org-element-type context) 'src-block) (string=3D (org-element-property :language context) "svg") (let ((beg (org-element-property :begin context)) (end (org-element-property :end context))) (if (org-clear-svg-preview beg end) (message "SVG preview removed") (message "Creating SVG preview...") (org-format-svg beg end) (message "Creating SVG preview... done.")) t)))))) (provide 'bob-org-svg)