From 565dd64e74b78f56982bd7ca92f34ab71e6d669a Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Thu, 13 Jul 2017 00:40:35 -0400 Subject: [PATCH v3 1/2] Let `function-put' affect compilation of the current file * lisp/emacs-lisp/bytecomp.el (byte-compile-plist-environment): New variable. (byte-compile-close-variables): Let-bind it to nil. (byte-compile-function-put): New byte-defop-compiler. * lisp/subr.el (function-get): Consult `byte-compile-plist-environment'. --- lisp/emacs-lisp/bytecomp.el | 18 ++++++++++++++++++ lisp/subr.el | 7 ++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index e5b9b47b1d..028efbce26 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -498,6 +498,10 @@ (defvar byte-compile-macro-environment byte-compile-initial-macro-environment Each element looks like (MACRONAME . DEFINITION). It is \(MACRONAME . nil) when a macro is redefined as a function.") +(defvar byte-compile-plist-environment nil + "Alist of property lists defined in the file being compiled. +Each element looks like (SYMBOL . PLIST).") + (defvar byte-compile-function-environment nil "Alist of functions defined in the file being compiled. This is so we can inline them when necessary. @@ -1585,6 +1589,7 @@ (defmacro byte-compile-close-variables (&rest body) ;; macroenvironment. (copy-alist byte-compile-initial-macro-environment)) (byte-compile--outbuffer nil) + (byte-compile-plist-environment nil) (byte-compile-function-environment nil) (byte-compile-bound-variables nil) (byte-compile-lexical-variables nil) @@ -4577,6 +4582,7 @@ (byte-defop-compiler-1 defvar) (byte-defop-compiler-1 defconst byte-compile-defvar) (byte-defop-compiler-1 autoload) (byte-defop-compiler-1 lambda byte-compile-lambda-form) +(byte-defop-compiler-1 function-put) ;; If foo.el declares `toto' as obsolete, it is likely that foo.el will ;; actually use `toto' in order for this obsolete variable to still work @@ -4725,6 +4731,18 @@ (put 'make-variable-buffer-local 'byte-hunk-handler 'byte-compile-form-make-variable-buffer-local) (defun byte-compile-form-make-variable-buffer-local (form) (byte-compile-keep-pending form 'byte-compile-normal-call)) + +(defun byte-compile-function-put (form) + (pcase form + (`(,_ (,(or 'quote 'function) ,(and fun (guard (symbolp fun)))) + ',prop ,(or `#',value (and value (guard (functionp value))))) + (let ((fplist (assq fun byte-compile-plist-environment))) + (if fplist + (setcdr fplist (plist-put (cdr fplist) prop value)) + (push (cons fun (list prop value)) + byte-compile-plist-environment))))) + (byte-compile-normal-call form)) + ;;; tags diff --git a/lisp/subr.el b/lisp/subr.el index 42b4e1c211..3e4a3dedf5 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2971,7 +2971,12 @@ (defun function-get (f prop &optional autoload) if it's an autoloaded macro." (let ((val nil)) (while (and (symbolp f) - (null (setq val (get f prop))) + (null (setq val (or (plist-get + (alist-get + f (bound-and-true-p + byte-compile-plist-environment)) + prop) + (get f prop)))) (fboundp f)) (let ((fundef (symbol-function f))) (if (and autoload (autoloadp fundef) -- 2.11.1