From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: replace letf with cl-letf in org-mime Date: Wed, 01 Apr 2015 10:17:02 +0800 Message-ID: <87384k619d.fsf@ericabrahamsen.net> References: <87wq29m8zm.fsf@ericabrahamsen.net> <87iodt2k3i.fsf@nicolasgoaziou.fr> <87619iopdj.fsf@ericabrahamsen.net> <87zj6txxbw.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yd8Dj-0002VX-4V for emacs-orgmode@gnu.org; Tue, 31 Mar 2015 22:17:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yd8Dd-0002SV-W5 for emacs-orgmode@gnu.org; Tue, 31 Mar 2015 22:17:31 -0400 Received: from plane.gmane.org ([80.91.229.3]:41108) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yd8Dd-0002SF-Ky for emacs-orgmode@gnu.org; Tue, 31 Mar 2015 22:17:25 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Yd8DW-0000EI-Ux for emacs-orgmode@gnu.org; Wed, 01 Apr 2015 04:17:19 +0200 Received: from 114.248.18.112 ([114.248.18.112]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 01 Apr 2015 04:17:18 +0200 Received: from eric by 114.248.18.112 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 01 Apr 2015 04:17:18 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Nicolas Goaziou writes: > Hello, > > Eric Abrahamsen writes: > >> Subject: [PATCH] org-mime.el: Avoid use of letf/cl-letf > > Thank you. Some comments follow. > >> + (let* ((mp (lambda (p)) (org-entry-get nil p org-mime-use-property-inheritance)) > > It should be > > (mp (lambda (p) (org-entry-get ....))) Whoops, dammit, I made the same mistake in both places, but somehow only fixed the second. >> + (let ((bhook >> + (lambda (body fmt) >> + (let ((hook (intern (concat "org-mime-pre-" >> + (symbol-name fmt) >> + "-hook")))) >> + (if (> (eval `(length ,hook)) 0) >> + (with-temp-buffer >> + (insert body) >> + (goto-char (point-min)) >> + (eval `(run-hooks ',hook)) >> + (buffer-string)) >> + body)))) > > Not really related to the patch but the `eval' in the definition above > looks wrong. Shouldn't it be > > (> (length hook) 0) > > and > > (run-hooks hook) That is weird. What's even weirder is the above doesn't work. I set up a test like this: (defun my-org-mime-hook () (message "hook!")) (add-hook 'org-mime-pre-org-hook 'my-org-mime-hook) If I remove the two `eval's and treat "hook" like a normal variable, the call to `length' fails with: Wrong type argument: sequencep, org-mime-pre-org-hook So apparently `length' is seeing the symbol name, and not the symbol value. I tried changing the `let' to look like: (let ((hook (symbol-value (intern (.... Now the value of "hook" is '(my-org-mime-hook). That works with the `length', and also with the `run-hooks', so long "hook" is quoted as in the original `eval' version: (run-hooks 'hook) Unfortunately, that means there are still some fundamental things I don't understand about how symbols work. Here's a fixed version of the previous patch. I suppose I could also alter the "bhook" thing to use `symbol-value' instead of `eval', but that doesn't seem to be a net gain. Thanks, Eric --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org-mime.el-Don-t-use-letf-or-cl-letf.patch >From 5901c2c696d3857f5f7a3c70b6de93f4f5974200 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Wed, 1 Apr 2015 10:08:34 +0800 Subject: [PATCH] org-mime.el: Don't use letf or cl-letf * contrib/lisp/org-mime.el (org-mime-send-subtree, org-mime-compose): `cl-letf' doesn't exist in Emacs <= 23, but `letf' won't exist in future Emacs. Replace with `lambda' and `funcall'. --- contrib/lisp/org-mime.el | 111 ++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 55 deletions(-) diff --git a/contrib/lisp/org-mime.el b/contrib/lisp/org-mime.el index f341474..1e7a3b8 100644 --- a/contrib/lisp/org-mime.el +++ b/contrib/lisp/org-mime.el @@ -252,22 +252,22 @@ export that region, otherwise export the entire body." (save-restriction (org-narrow-to-subtree) (run-hooks 'org-mime-send-subtree-hook) - (flet ((mp (p) (org-entry-get nil p org-mime-use-property-inheritance))) - (let* ((file (buffer-file-name (current-buffer))) - (subject (or (mp "MAIL_SUBJECT") (nth 4 (org-heading-components)))) - (to (mp "MAIL_TO")) - (cc (mp "MAIL_CC")) - (bcc (mp "MAIL_BCC")) - (body (buffer-substring - (save-excursion (goto-char (point-min)) - (forward-line 1) - (when (looking-at "[ \t]*:PROPERTIES:") - (re-search-forward ":END:" nil) - (forward-char)) - (point)) - (point-max)))) - (org-mime-compose body (or fmt 'org) file to subject - `((cc . ,cc) (bcc . ,bcc))))))) + (let* ((mp (lambda (p) (org-entry-get nil p org-mime-use-property-inheritance))) + (file (buffer-file-name (current-buffer))) + (subject (or (funcall mp "MAIL_SUBJECT") (nth 4 (org-heading-components)))) + (to (funcall mp "MAIL_TO")) + (cc (funcall mp "MAIL_CC")) + (bcc (funcall mp "MAIL_BCC")) + (body (buffer-substring + (save-excursion (goto-char (point-min)) + (forward-line 1) + (when (looking-at "[ \t]*:PROPERTIES:") + (re-search-forward ":END:" nil) + (forward-char)) + (point)) + (point-max)))) + (org-mime-compose body (or fmt 'org) file to subject + `((cc . ,cc) (bcc . ,bcc)))))) (defun org-mime-send-buffer (&optional fmt) (run-hooks 'org-mime-send-buffer-hook) @@ -287,45 +287,46 @@ export that region, otherwise export the entire body." (require 'message) (message-mail to subject headers nil) (message-goto-body) - (flet ((bhook (body fmt) - (let ((hook (intern (concat "org-mime-pre-" - (symbol-name fmt) - "-hook")))) - (if (> (eval `(length ,hook)) 0) - (with-temp-buffer - (insert body) - (goto-char (point-min)) - (eval `(run-hooks ',hook)) - (buffer-string)) - body)))) - (let ((fmt (if (symbolp fmt) fmt (intern fmt)))) - (cond - ((eq fmt 'org) - (require 'ox-org) - (insert (org-export-string-as - (org-babel-trim (bhook body 'org)) 'org t))) - ((eq fmt 'ascii) - (require 'ox-ascii) - (insert (org-export-string-as - (concat "#+Title:\n" (bhook body 'ascii)) 'ascii t))) - ((or (eq fmt 'html) (eq fmt 'html-ascii)) - (require 'ox-ascii) - (require 'ox-org) - (let* ((org-link-file-path-type 'absolute) - ;; we probably don't want to export a huge style file - (org-export-htmlize-output-type 'inline-css) - (html-and-images - (org-mime-replace-images - (org-export-string-as (bhook body 'html) 'html t) file)) - (images (cdr html-and-images)) - (html (org-mime-apply-html-hook (car html-and-images)))) - (insert (org-mime-multipart - (org-export-string-as - (org-babel-trim - (bhook body (if (eq fmt 'html) 'org 'ascii))) - (if (eq fmt 'html) 'org 'ascii) t) - html) - (mapconcat 'identity images "\n")))))))) + (let ((bhook + (lambda (body fmt) + (let ((hook (intern (concat "org-mime-pre-" + (symbol-name fmt) + "-hook")))) + (if (> (eval `(length ,hook)) 0) + (with-temp-buffer + (insert body) + (goto-char (point-min)) + (eval `(run-hooks ',hook)) + (buffer-string)) + body)))) + (fmt (if (symbolp fmt) fmt (intern fmt)))) + (cond + ((eq fmt 'org) + (require 'ox-org) + (insert (org-export-string-as + (org-babel-trim (funcall bhook body 'org)) 'org t))) + ((eq fmt 'ascii) + (require 'ox-ascii) + (insert (org-export-string-as + (concat "#+Title:\n" (funcall bhook body 'ascii)) 'ascii t))) + ((or (eq fmt 'html) (eq fmt 'html-ascii)) + (require 'ox-ascii) + (require 'ox-org) + (let* ((org-link-file-path-type 'absolute) + ;; we probably don't want to export a huge style file + (org-export-htmlize-output-type 'inline-css) + (html-and-images + (org-mime-replace-images + (org-export-string-as (funcall bhook body 'html) 'html t) file)) + (images (cdr html-and-images)) + (html (org-mime-apply-html-hook (car html-and-images)))) + (insert (org-mime-multipart + (org-export-string-as + (org-babel-trim + (funcall bhook body (if (eq fmt 'html) 'org 'ascii))) + (if (eq fmt 'html) 'org 'ascii) t) + html) + (mapconcat 'identity images "\n"))))))) (defun org-mime-org-buffer-htmlize () "Create an email buffer containing the current org-mode file -- 2.3.5 --=-=-=--