From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: torys.anderson@gmail.com (Tory S. Anderson) Newsgroups: gmane.emacs.help Subject: Possible to conditionally bind variable? Date: Thu, 11 Sep 2014 07:11:41 -0400 Message-ID: <87lhpq8l8y.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1410433936 15658 80.91.229.3 (11 Sep 2014 11:12:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Sep 2014 11:12:16 +0000 (UTC) To: emacs list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Sep 11 13:12:08 2014 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 1XS2IC-0000yO-Ak for geh-help-gnu-emacs@m.gmane.org; Thu, 11 Sep 2014 13:12:00 +0200 Original-Received: from localhost ([::1]:36121 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XS2IB-0004VC-T2 for geh-help-gnu-emacs@m.gmane.org; Thu, 11 Sep 2014 07:11:59 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XS2Hx-0004Ui-5F for help-gnu-emacs@gnu.org; Thu, 11 Sep 2014 07:11:46 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XS2Hv-0002gP-DI for help-gnu-emacs@gnu.org; Thu, 11 Sep 2014 07:11:45 -0400 Original-Received: from mail-yk0-x22c.google.com ([2607:f8b0:4002:c07::22c]:37050) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XS2Hv-0002gG-9E for help-gnu-emacs@gnu.org; Thu, 11 Sep 2014 07:11:43 -0400 Original-Received: by mail-yk0-f172.google.com with SMTP id q9so3747568ykb.17 for ; Thu, 11 Sep 2014 04:11:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type; bh=MAP6vye5w73WpAup3twRhnPVEQCXWoE5z4+4CCnzXII=; b=cVO6BqOnoBnziJIJMcwK/XR6oSMcH53BsBB3HAt93jiZDm3ZzDEENIYOQ8UiMj+cdJ sZ6nirK5DWoeXh9Zhy6bOHOEQ2zS53Foh8Utllg3UWUKTIVqnTO+Jd8Y8Hf7nQ3z2Skg qorHLhr3sq43QPTpdTzEYaFPNFFtwCd8s46RWQxy02fjPYQG0e7hY5IS2zA5j9f4kcRm Y/AEQ/cOtR+Z7N9vEMdh0D7zlr/OKdbwfrubqfea3XGGlHsRq3mjXE2dkI+P6zG0t/ps Jn2Xj5iNLf/xUGHnw6PGTSYC/gezGHro4GVCM5OdxfPkyRfoyLpvJG0amKqjgnYFx/Xv OcZQ== X-Received: by 10.236.118.207 with SMTP id l55mr192359yhh.178.1410433902758; Thu, 11 Sep 2014 04:11:42 -0700 (PDT) Original-Received: from localhost.localdomain ([2601:0:a000:4a1:ee55:f9ff:feb5:5589]) by mx.google.com with ESMTPSA id a30sm203523yho.37.2014.09.11.04.11.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Sep 2014 04:11:42 -0700 (PDT) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4002:c07::22c 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:99808 Archived-At: I have several redundancies in the following code: (defun go-or-make-agenda (&optional new-frame) (interactive "P") (let ((buffer "\*Org Agenda\*")) (if (get-buffer buffer) (if new-frame (switch-to-buffer-other-frame buffer) (switch-to-buffer buffer)) (if new-frame (switch-to-buffer-other-frame org-agenda-list) (org-agenda-list))))) I'd like to do something like the following, to chop out much of the switch-to-[other-]-buffer cruft: (defun go-or-make-agenda (&optional new-frame) (interactive "P") (let ((buffer "\*Org Agenda\*") (some-other-buffer "*scratch*") (my-switch-function (if new-frame ;; is there some way to do this? '(switch-to-other-buffer) '(switch-to-buffer))) (if (get-buffer buffer) (my-switch-function buffer) (my-switch-function some-other-buffer))))) I'm not sure this is possible (short of the rather daunting http://stackoverflow.com/questions/25115876/conditional-variable-binding-in-common-lisp), but I have trust that in the awesomeness of Lisp it just might be. - Tory