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: My advice-add :filter-args does not work Date: Sat, 6 Jan 2018 19:12:33 +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 1515237122 30623 195.159.176.226 (6 Jan 2018 11:12:02 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 6 Jan 2018 11:12:02 +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:11:58 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 1eXmOB-00079A-D9 for geh-help-gnu-emacs@m.gmane.org; Sat, 06 Jan 2018 12:11:47 +0100 Original-Received: from localhost ([::1]:59583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXmQ9-0007xt-14 for geh-help-gnu-emacs@m.gmane.org; Sat, 06 Jan 2018 06:13:49 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37061) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXmPT-0007xE-Ca for help-gnu-emacs@gnu.org; Sat, 06 Jan 2018 06:13:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eXmPQ-0006Kg-RL for help-gnu-emacs@gnu.org; Sat, 06 Jan 2018 06:13:07 -0500 Original-Received: from mail-ot0-x241.google.com ([2607:f8b0:4003:c0f::241]:35352) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eXmPQ-0006K2-KU for help-gnu-emacs@gnu.org; Sat, 06 Jan 2018 06:13:04 -0500 Original-Received: by mail-ot0-x241.google.com with SMTP id q5so5909790oth.2 for ; Sat, 06 Jan 2018 03:13:04 -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=Ni+fN7AS9Es6MTK2ySWEMFpTqHLZguTepFScb/7u6lY=; b=SSZQdLzwQY1GRT8NkO44TjGUXLjxYi8MrVEes/1Q0ji5tivL9PbKm3Oa4z1tiXhJXT CMbvh5TwRO1ijl0F1nMoBleHCZpUS9cjz359Ibxgr1oUvIUNDJPXMfCR5IeJt1f5Ai57 vg1uI4XXhCwW2fhUYQ2Tvs75NwlnMCZdkZMF5vKTed2G6ihCYRUKes0xBql0GlLXKv+H Bi2e/TBQb9f7Zc/frK/9InoYkabtWpmiVcz12Dq/C39+O/ho3scdNXjTICG5wbd/gYbc XfXt5iP8uQqvMRCUQbe35akVSLQVDzgWU/QhloVk6filifTpEA1C2Tc2/PvofLoX3dkl yP+Q== 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=Ni+fN7AS9Es6MTK2ySWEMFpTqHLZguTepFScb/7u6lY=; b=eXhbFmfSip0rWxsYzAsUt1UjOdTqbjswa9Sz0PjsvRJyVc+bnfz4idG0MRFWHWVyjZ j266qiEPCGHJ38oXb8gF6sHm1qTxUaG4r8qEJCDGQZ+tYzKLwDHHnsK/Ju6iu2vnMqHj QEaYFYypT5mMJf5REeLLUbwIuGIWWUVSzcvl0JAccAceuUXqgzT9fksBfRgZNSIX65AV LnRVJLQ7i8vRRx4x2xJcDyzyQ4Gc48TvczSlLKVnde9LS6GQDQMcEnkhkdoKkx8V9esq D9j/4HfkX2swbe5ZHwUa0RuJrZWdrvem7d8JYwwq02DQ54M5yiNDn4AKIgWPizfixicx 4nqw== X-Gm-Message-State: AKwxytcSLLNxMgKlKlpp+TP1d+NJPJ3pMjODRiX4A+Pu8bDkZdFh06rQ ZKf1ViUZa9nZFcZk0dhCSDdnQaAXt4A/ijp80Qdd+98= X-Google-Smtp-Source: ACJfBovcfLGVlYkr02GobzFk6PpG9jxqYdkgY/rN0gV6HgLrp9+st+Cx/0c0jKnzPppXz4yAH2aZ+4M4oySh7aLTXFg= X-Received: by 10.157.26.52 with SMTP id a49mr3196398ote.238.1515237183457; Sat, 06 Jan 2018 03:13:03 -0800 (PST) Original-Received: by 10.157.42.19 with HTTP; Sat, 6 Jan 2018 03:12:33 -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:115601 Archived-At: As this question described https://emacs.stackexchange.com/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-color) ``` 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/