From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lennart Borgman Newsgroups: gmane.emacs.devel Subject: Why don't let bound values die? Date: Fri, 3 Sep 2010 20:11:28 +0200 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: dough.gmane.org 1283537527 24205 80.91.229.12 (3 Sep 2010 18:12:07 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 3 Sep 2010 18:12:07 +0000 (UTC) To: Emacs-Devel devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Sep 03 20:12:05 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Orak5-0005hX-Jt for ged-emacs-devel@m.gmane.org; Fri, 03 Sep 2010 20:12:02 +0200 Original-Received: from localhost ([127.0.0.1]:37208 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Orak4-0001EF-QN for ged-emacs-devel@m.gmane.org; Fri, 03 Sep 2010 14:12:00 -0400 Original-Received: from [140.186.70.92] (port=58870 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Orajv-0001C4-60 for emacs-devel@gnu.org; Fri, 03 Sep 2010 14:11:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Orajt-0006wn-VQ for emacs-devel@gnu.org; Fri, 03 Sep 2010 14:11:50 -0400 Original-Received: from mail-qy0-f176.google.com ([209.85.216.176]:33902) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Orajt-0006we-TA for emacs-devel@gnu.org; Fri, 03 Sep 2010 14:11:49 -0400 Original-Received: by qyk2 with SMTP id 2so2402266qyk.0 for ; Fri, 03 Sep 2010 11:11:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:from:date :message-id:subject:to:content-type; bh=lpcoqmLF+3Gl/uLBah+MeSxMxomzxgIyy+RR4lVkNl4=; b=dMywLCDRFEJk8pMqDZirwzEO/lsrt6nmpHdUzgQfxVIUPUNC/4wWyGHIxZXCGXiAjT wzk+h4UEMQLSh9wDOcD+1n77qUTRk7cQFIZoqOd019Uqk+82a+QQzmYgHsNmspScmV7u vp/c04HFVdINiXb/An+6MYL7/LWQJ+VzcT30E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=YH9Tle20mJdG8RwbYI1a70Z34pw5p7UJDJRk+EkfCG2VYtGQ4bST/1pWm5LcRf2Yh8 ruqVQbPjZuPcE67v78/qCcwB8qnzR02Lf01NC3/vHKlB1xLgOiz6MNF34byyKAuIXY1g xwB6+nHgw7HuSo4l+qhVwNJCitCH5qAhIuTjo= Original-Received: by 10.224.6.145 with SMTP id 17mr248391qaz.140.1283537509340; Fri, 03 Sep 2010 11:11:49 -0700 (PDT) Original-Received: by 10.229.27.133 with HTTP; Fri, 3 Sep 2010 11:11:28 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:129655 Archived-At: I have a small utility in nXhtml to save commands accessed through the menus to M-x history list. (We discussed such a feature here a while ago.) Recently I noticed problems with menu items defined by easymenu. Org-mode uses this, for example to define the menu item "Org - Hyperlinks - Literal links". When accessing this menu item a temporary command symbol is set up (if I understand this correctly), something like menu-function-21. This symbol then shows up in this-command (in pre-command-hook). (BTW, it is in my opinion a bit annoying that anonymous functions are used in the menus. Should not at least easymenu discourage this?) I tried to avoid adding such symbols like menu-function-21 to the history list. I thought it would be gone if I looked for it in a run-with-idle-timer timer, but it is not. I do not understand why and would be glad for an explanation. (I fixed it by saving the symbol name and checking for it with intern-soft.) Here is the code in question: (defvar ourcomments-M-x-menu-timer nil) (defvar ourcomments-M-x-menu-this-command nil) (defun ourcomments-M-x-menu-pre () "Add menu command to M-x history." (let ((is-menu-command (equal '(menu-bar) (when (< 0 (length (this-command-keys-vector))) (elt (this-command-keys-vector) 0))))) (when (and is-menu-command (not (memq this-command '(ourcomments-M-x-menu-mode)))) (when (timerp ourcomments-M-x-menu-timer) (cancel-timer ourcomments-M-x-menu-timer)) (message "this-command=%s" this-command) (setq ourcomments-M-x-menu-this-command (symbol-name this-command)) (setq ourcomments-M-x-menu-timer (run-with-idle-timer 3 nil 'ourcomments-M-x-menu-in-timer))))) (defun ourcomments-M-x-menu-in-timer () "Add MAYBE-COMMAND to M-x history if it is a command." (condition-case err (ourcomments-M-x-menu-in-timer-1) (error (message "M-x-menu-in-timer ERROR: %s" (error-message-string err))))) (defun ourcomments-M-x-menu-in-timer-1 () (setq ourcomments-M-x-menu-timer nil) ;; Fix-me: temporary commands, like from "Org - Hyperlinks - Literal ;; links" are still defined here, why??? ;; Using symbol-name + intern-soft helped, but why is it necessary? (let ((maybe-command (intern-soft ourcomments-M-x-menu-this-command))) (message "maybe-command=%s, %s" maybe-command (commandp maybe-command)) ;; this-command could have been let bound so check it: (when (commandp maybe-command) (let ((pre-len (length extended-command-history))) (pushnew (symbol-name maybe-command) extended-command-history) (when (< pre-len (length extended-command-history)) ;; Give a temporary message (let ((msg (format "(Added %s to M-x history so you can run it from there)" maybe-command))) (with-temp-message (propertize msg 'face 'file-name-shadow) (sit-for 3)))))))) ;;;###autoload (define-minor-mode ourcomments-M-x-menu-mode "Add commands started from Emacs menus to M-x history. The purpose of this is to make it easier to redo them and easier to learn how to do them from the command line \(which is often faster if you know how to do it). Only commands that are not already in M-x history are added." :global t (if ourcomments-M-x-menu-mode (add-hook 'pre-command-hook 'ourcomments-M-x-menu-pre) (remove-hook 'pre-command-hook 'ourcomments-M-x-menu-pre)))