From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Narendra Joshi Newsgroups: gmane.emacs.help Subject: Macro for defining a lineup of commands Date: Mon, 26 Jun 2017 14:29:31 +0530 Message-ID: <87efu7jf9o.fsf@vicarie> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1498467606 22488 195.159.176.226 (26 Jun 2017 09:00:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 26 Jun 2017 09:00:06 +0000 (UTC) To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jun 26 10:59:58 2017 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 1dPPsA-0005Ip-TI for geh-help-gnu-emacs@m.gmane.org; Mon, 26 Jun 2017 10:59:55 +0200 Original-Received: from localhost ([::1]:45363 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPPsG-0001u4-0r for geh-help-gnu-emacs@m.gmane.org; Mon, 26 Jun 2017 05:00:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46228) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPPrO-0001tl-R5 for help-gnu-emacs@gnu.org; Mon, 26 Jun 2017 04:59:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPPrH-0004NW-VP for help-gnu-emacs@gnu.org; Mon, 26 Jun 2017 04:59:03 -0400 Original-Received: from mail-pf0-x232.google.com ([2607:f8b0:400e:c00::232]:33529) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dPPrH-0004N1-PJ for help-gnu-emacs@gnu.org; Mon, 26 Jun 2017 04:58:59 -0400 Original-Received: by mail-pf0-x232.google.com with SMTP id e7so52040569pfk.0 for ; Mon, 26 Jun 2017 01:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=PhSSywZePwf6cm3bRR1YHoAGtna5ipcREftlR5cMJLc=; b=kL006WMI+CLK4xdoz3UmcLtyO6uOOC8PqHqfcuOl9jsgdtCimubv2xOGvayrCwQJMz RYiRDcWS4/6j5p8a8zjvE6+HrYDx/zccG3a0NAltIMUf9c5b4CXCBr9lvBBu9omflzli EKBy+DeWUvKz8D4GqAaycMGstVSS5fBiF4UMruHQXJCI46xXeczAMj/yA3nAp7kMZRyk DtkpFK3sRhmbEbpCoxSdpOAVxucSjoM2DCpb7EAMCM/Cdyx6z/BzWdUELTqIAFgrS6S1 C7Uyv0+2onbSWif4y1tK+WqTuZPpvZJKH7Arm2rkAmpuu5k1CyQ8wHOiwla40CgZmdvI G1cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=PhSSywZePwf6cm3bRR1YHoAGtna5ipcREftlR5cMJLc=; b=iJ93fHXwacvXNiuFB0ZvFaS0AVYyzSdVdAHBUxQUVeAlSISZ47w0MpCuifJM0zUfKo OTr2IuK/VNngL3W4o6CyNMRtoPwRBUhk5Wj6PpPs8kWQF+iVIYR+VWi8fOGcqLw1qyr5 wqbtHu3bscMD8DwMdtK1Xm/LKd388NKzcXYS4mpb+17IjR+YlWYllBZzgrgoeMfAujR3 ZtQ9+pRHFttYLqAxKxvDjU6gmDvow3gw5VO3pJ1u3a5RaZV6+SR74pSUAAlDgJ4XpGZA /en4gJeGy5QUQXeQ3G41blTzYIZR+1pirw896hwYHwpzNsSVyJ09ICwg67vIMIbVFtAq C/bw== X-Gm-Message-State: AKS2vOxd5Akc4Vn5GPFvTxr7HymT6x5rMRMeyY9EkoUEU0fRc5/w/Mek S6FH5nYcwM8xFvQJ X-Received: by 10.98.66.77 with SMTP id p74mr20626116pfa.240.1498467536962; Mon, 26 Jun 2017 01:58:56 -0700 (PDT) Original-Received: from vicarie ([182.70.0.144]) by smtp.gmail.com with ESMTPSA id s7sm14358112pgb.53.2017.06.26.01.58.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Jun 2017 01:58:56 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::232 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:113573 Archived-At: Hi, I want to share a macro that I wrote recently. I really like it. I would like to have suggestions to improve it and new use cases. :) If there are better and more general alternatives to this, it would be great to know. :) ,---- | (defmacro def-lineup (command docstring &rest commands) | "Make a COMMAND with DOCSTRING to run COMMANDS in order on repeated usage. | Currently works for commands that need no interactive input. It | automatically makes the sequence a circular sequence | logically. That's because `(car nil)' equals nil. | | Argument DOCSTRING would serve as the docstring for COMMAND. | | Example usage: | \(def-lineup fill-unfill | \"Cycle between filling a line, filling a para and unfill.\" | #'auto-fill-current-line #'fill-paragraph #'unfill-paragraph) | | This would define a new command with the name fill-unfill that | would run commands in '(auto-fill-current-line fill-paragraph unfill-paragraph) | one after the other in a circular fashion, when called repeatedly." | `(defun ,command () ,docstring | (interactive) | (let* ((command-sequence | (if-let ((cseq (get this-command 'command-sequence)) | (_ (eq last-command this-command))) | cseq | (list ,@commands))) | (next-command (car command-sequence))) | (message (format "-> %s" next-command)) | (call-interactively next-command) | (put this-command 'command-sequence (cdr command-sequence))))) `---- Best, -- Narendra Joshi