From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Raffaele Ricciardi Newsgroups: gmane.emacs.help Subject: Re: Convert an existing keyboard macro to elisp code? Date: Sat, 04 Aug 2012 10:48:47 +0100 Message-ID: References: <87mx2cxb7x.fsf@googlemail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1344070212 13242 80.91.229.3 (4 Aug 2012 08:50:12 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 4 Aug 2012 08:50:12 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Aug 04 10:50:12 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sxa3o-0003db-KQ for geh-help-gnu-emacs@m.gmane.org; Sat, 04 Aug 2012 10:50:12 +0200 Original-Received: from localhost ([::1]:42067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sxa3n-0006oO-SD for geh-help-gnu-emacs@m.gmane.org; Sat, 04 Aug 2012 04:50:11 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 67 Original-X-Trace: individual.net 6QCmPHtlTKi47CQQLswqdwiVwcntdSsbNP46IEFjVHlw0D76ZGCAvY7u+pp1Ec9aKc Cancel-Lock: sha1:/Jc1OlV6myJnChyINf3OQq/Hhfo= User-Agent: Mozilla/5.0 (X11; Linux i686; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: Original-Xref: usenet.stanford.edu gnu.emacs.help:193824 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:86195 Archived-At: On 08/03/2012 05:33 PM, PJ Weisberg wrote:> On Fri, Aug 3, 2012 at 8:10 AM, Thorsten Jolitz wrote: >> Unfortunately, the answer was more a less a 'NO'(or 'YOU HAVE TO WRITE >> IT YOURSELF'). >> >> Since Emacs is a pretty dynamic project, I thought I give it another try >> on the mailing list - maybe this feature request has been implemented in >> the meantime by somebody? > > If it were just a matter of reading the key sequence and mapping it to > functions it wouldn't be too bad, but the more I think about this, the > more it seems like a rat hole. How would you translate > > (fset 'my-macro > [?\M-x ?m ?a ?g tab ?i ?t tab ?s ?t tab ?t tab return ?m ?a tab return]) > > into > > (defun my-macro () > (interactive) > (magit-status "c:/Users/PJ/Documents/magit/")) > > ? > > You would need to know what auto-completion happened when the user > pressed tab, and then you would need to know how the function > translated its user input into interactive arguments. I don't think > there's a way to do it without running the macro and (somehow) > watching what happens. And that could have unpleasant side effects. > > And this particular example wouldn't even be portable, since when I > type "M-x magit-status RET magit RET", Magit actually does some magic > to translate that into a full path. So on my other machine, the > proper definition of that macro would be > > (defun my-macro () > (interactive) > (magit-status "/home/pj/source-code/magit")) > > > And that doesn't even take into account different keymaps. > > -PJ > > Gehm's Corollary to Clark's Law: Any technology distinguishable from > magic is insufficiently advanced. > Be stumped: C-h f command-history C-h v command-history Emacs already keeps track of commands that read input from terminal, I don't see the reason it couldn't keep track of all commands, as the third-party library mwe-log-commands.el does it, while discarding the arguments. Maybe Emacs does it already in some other variable I don't know. Regarding commands requiring further input and possibly performing conversions on their own, Emacs could feed them the same input you did. Of course, the resulting translation will be context-sensitive just like the original macro was. Adjustments to make the code portable would be up to the user.