From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "numbchild@gmail.com" Newsgroups: gmane.emacs.help Subject: [FIXED] Re: My advice-add :filter-args does not work Date: Sat, 6 Jan 2018 19:53:26 +0800 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1515239556 26894 195.159.176.226 (6 Jan 2018 11:52:36 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 6 Jan 2018 11:52:36 +0000 (UTC) To: emacs-help Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jan 06 12:52:32 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXn1V-0006F1-O4 for geh-help-gnu-emacs@m.gmane.org; Sat, 06 Jan 2018 12:52:25 +0100 Original-Received: from localhost ([::1]:60929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXn3V-0000jU-01 for geh-help-gnu-emacs@m.gmane.org; Sat, 06 Jan 2018 06:54:29 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59375) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXn32-0000j8-4t for help-gnu-emacs@gnu.org; Sat, 06 Jan 2018 06:54:02 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eXn2z-00039y-Sg for help-gnu-emacs@gnu.org; Sat, 06 Jan 2018 06:54:00 -0500 Original-Received: from mail-ot0-x241.google.com ([2607:f8b0:4003:c0f::241]:35511) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eXn2z-00039T-KL for help-gnu-emacs@gnu.org; Sat, 06 Jan 2018 06:53:57 -0500 Original-Received: by mail-ot0-x241.google.com with SMTP id q5so5949546oth.2 for ; Sat, 06 Jan 2018 03:53:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=AeXowinu3Q1Ikk9Zk/mw7BR9C+GlFCCD+JMKA99f9nw=; b=ZEMc82Voooyf7RZH4C5CweYMV0b2I1owQ9l0skUCjxfZic9G+UmdtlMIeieNJit8Cz WiLEjapw24Qad0sfMofJR3nDPY6Kizd9a9TZSxSx1XjYDPg2cJudVg5YmwMa7zbnwj90 qWAIs0/Ri/+t/SN+K0ne6ZXJ37iIg5RY83KUox31hPhl8GvsZQqBAylDdMagvP2/U7wR WCeggmJtJhNKfmcTSCRSxEgUtPXEvdMwF04cdv2ZEgVuHNU+YQgpRQZJvTHdaPTdlwQN 3DL7lnhYt/93o+NWY3fKCvirwJLzUYdhwyEcjLVzyDlBRAO1lpV4du6dKyStujErXnj1 IHPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=AeXowinu3Q1Ikk9Zk/mw7BR9C+GlFCCD+JMKA99f9nw=; b=mZLSPGtwYtWN0ntTfoPQkyOxO0VkaPasxnRWSYtAjKJfDmYhFjir6CGSCBeXYfSddI AQ3ArobyVwPp889Kipk6+8BGsF5F3zPpuGeuMR44G4wltBWnkv1nxSvowdX8lqY3mjQ7 sXMa6ofuM08KGVOUqo/YeMOvBnso7c9IHVmyq3vwTA6a7ZQErZAPfZuNeDVfOzzMJBNw huoYkHZ80Kgd1CJdFMEOdoqgmzLPbGfL33KFbQ2Q8Q7sfXf0fu2iT6V7dmpU/Nc/U3+0 itwkwyJK3ZGAsY8qV+HByOzMYBWB+H6culgTIRjIoDVS3DdK1TB7/m/bg+KA/TIVuMs+ ASsw== X-Gm-Message-State: AKwxytdwkydxMHbrjF7byVMYTZtc+ngKj1bU3cP+ldc53l2M4yT+z+s2 PvHheGoa2cRMODB5P8Du8/vs4T+J/0Hst228fweq X-Google-Smtp-Source: ACJfBosi723lorNqP3nm4QzQjHeoVWIRmnFvY4C/SAWEvGLdtXBtUbO72NTz11Qfj2v9x4R6e//TVq9HBFDFSQw50hA= X-Received: by 10.157.42.97 with SMTP id t88mr3843431ota.211.1515239636492; Sat, 06 Jan 2018 03:53:56 -0800 (PST) Original-Received: by 10.157.42.19 with HTTP; Sat, 6 Jan 2018 03:53:26 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c0f::241 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:115602 Archived-At: I fixed my own problem. After check out function `create-image`. I found it need to return a plist. Here is the correct version: ```elisp (defun org-display-inline-images--with-color-theme-background-color (args) "Specify background color of Org-mode inline image through modify `ARGS'." (let* ((file (car args)) (type (cadr args)) (data-p (caddr args)) (props (cdddr args))) ;; get this return result style from `create-image' (append (list file type data-p) (list :background (face-background 'default)) props))) (advice-add 'create-image :filter-args #'org-display-inline-images--with-color-theme-background-color) ``` [stardiviner] GPG key ID: 47C32433 IRC(freeenode): stardiviner Twitter: @numbchild Key fingerprint = 9BAA 92BC CDDD B9EF 3B36 CB99 B8C4 B8E5 47C3 2433 Blog: http://stardiviner.github.io/ On Sat, Jan 6, 2018 at 7:12 PM, numbchild@gmail.com wrote: > As this question described https://emacs.stackexchange.co > m/questions/20574/default-inline-image-background-in-org- > mode/20598?noredirect=1#comment32673_20598 > > I'm going to modify the Org-mode inline images background colour. The > question's solution is define the original function again. > > ```elisp > ;;; set default Org-mode inline image background color. > (defcustom org-inline-image-background nil > "The color used as the default background for inline images. > When nil, use the default face background." > :group 'org > :type '(choice color (const nil))) > > ;;; set default background color based on different stategies. > (defun my-org-mode-image-set-face (&args) > (setq org-inline-image-background > ;; a static color. > ;; "#FFFFFF" > ;; same color with color-theme background. > (face-background 'default) > )) > > (add-hook 'circadian-after-load-theme-hook #'my-org-mode-image-set-face) > > (defun org-display-inline-images (&optional include-linked refresh beg end) > "Modified version of original `org-display-inline-images'. > Append `:background' in `create-image'." > (interactive "P") > (when (display-graphic-p) > (unless refresh > (org-remove-inline-images) > (when (fboundp 'clear-image-cache) (clear-image-cache))) > (org-with-wide-buffer > (goto-char (or beg (point-min))) > (let ((case-fold-search t) > (file-extension-re (image-file-name-regexp))) > (while (re-search-forward "[][]\\[\\(?:file\\|[./~]\\)" end t) > (let ((link (save-match-data (org-element-context)))) > ;; Check if we're at an inline image. > (when (and (equal (org-element-property :type link) "file") > (or include-linked > (not (org-element-property :contents-begin > link))) > (let ((parent (org-element-property :parent link))) > (or (not (eq (org-element-type parent) 'link)) > (not (cdr (org-element-contents parent))))) > (org-string-match-p file-extension-re > (org-element-property :path > link))) > (let ((file (expand-file-name > (org-link-unescape > (org-element-property :path link))))) > (when (file-exists-p file) > (let ((width > ;; Apply `org-image-actual-width' specifications. > (cond > ((not (image-type-available-p 'imagemagick)) nil) > ((eq org-image-actual-width t) nil) > ((listp org-image-actual-width) > (or > ;; First try to find a width among > ;; attributes associated to the paragraph > ;; containing link. > (let ((paragraph > (let ((e link)) > (while (and (setq e > (org-element-property > :parent e)) > (not (eq > (org-element-type e) > 'paragraph)))) > e))) > (when paragraph > (save-excursion > (goto-char (org-element-property :begin > paragraph)) > (when > (re-search-forward > "^[ \t]*#\\+attr_.*?: +.*?:width > +\\(\\S-+\\)" > (org-element-property > :post-affiliated paragraph) > t) > (string-to-number (match-string 1)))))) > ;; Otherwise, fall-back to provided number. > (car org-image-actual-width))) > ((numberp org-image-actual-width) > org-image-actual-width))) > (old (get-char-property-and-overlay > (org-element-property :begin link) > 'org-image-overlay))) > (if (and (car-safe old) refresh) > (image-refresh (overlay-get (cdr old) 'display)) > (let ((image (create-image file > (and width 'imagemagick) > nil > :width width > :background > org-inline-image-background))) ; added here. > (when image > (let* ((link > ;; If inline image is the description > ;; of another link, be sure to > ;; consider the latter as the one to > ;; apply the overlay on. > (let ((parent > (org-element-property :parent > link))) > (if (eq (org-element-type parent) > 'link) > parent > link))) > (ov (make-overlay > (org-element-property :begin link) > (progn > (goto-char > (org-element-property :end link)) > (skip-chars-backward " \t") > (point))))) > (overlay-put ov 'display image) > (overlay-put ov 'face 'default) > (overlay-put ov 'org-image-overlay t) > (overlay-put > ov 'modification-hooks > (list 'org-display-inline-remove-overlay)) > (push ov org-inline-image-overlays))))) > )))))))))) > ``` > > I don't like this solution. Try to use advice. But I'm not good at Elisp. > So I tried some search on Google and GitHub code. Try to understand some > examples. I try this code snippet: > > ```elisp > (defun org-display-inline-images--with-color-theme-background-color > (args) ; (file-or-data &optional type data-p &rest props) > "Specify background color of Org-mode inline image through modify > `ARGS'." > (let* ((file (car args)) > (type (cadr args)) > (data-p (caddr args)) > (props (cdddr args))) > (list file type data-p (append (list :background (face-background > 'default)) props)))) > > (advice-add 'create-image :filter-args > #'org-display-inline-images--with-color-theme-background-col > or) > > ``` > But it does not work. > > Hope someone can help me to fix this advice. > > [stardiviner] GPG key ID: 47C32433 > IRC(freeenode): stardiviner Twitter: @numbchild > Key fingerprint = 9BAA 92BC CDDD B9EF 3B36 CB99 B8C4 B8E5 47C3 2433 > Blog: http://stardiviner.github.io/ >