From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: dont.spam.earl@gmail.com Newsgroups: gmane.emacs.help Subject: Specifying arguments to interactive functions Date: Wed, 14 May 2014 22:20:51 -0700 (PDT) Message-ID: <5d6e3672-b901-4e59-852d-281a3a5e4733@googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1400132168 23930 80.91.229.3 (15 May 2014 05:36:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 15 May 2014 05:36:08 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu May 15 07:36:01 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 1WkoKl-0001Ad-Pq for geh-help-gnu-emacs@m.gmane.org; Thu, 15 May 2014 07:35:59 +0200 Original-Received: from localhost ([::1]:55720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkoKl-0008Am-6E for geh-help-gnu-emacs@m.gmane.org; Thu, 15 May 2014 01:35:59 -0400 X-Received: by 10.66.157.35 with SMTP id wj3mr1563231pab.11.1400131252272; Wed, 14 May 2014 22:20:52 -0700 (PDT) X-Received: by 10.50.142.106 with SMTP id rv10mr15208igb.3.1400131252176; Wed, 14 May 2014 22:20:52 -0700 (PDT) Original-Path: usenet.stanford.edu!c1no6998455igq.0!news-out.google.com!qf4ni926igc.0!nntp.google.com!c1no6998454igq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2602:306:cdd1:1270:c199:afe5:e7ad:d059; posting-account=QyAvTQoAAADtRdvZ5VbKTpUdY2nZ1GFk Original-NNTP-Posting-Host: 2602:306:cdd1:1270:c199:afe5:e7ad:d059 User-Agent: G2/1.0 Injection-Date: Thu, 15 May 2014 05:20:52 +0000 Original-Xref: usenet.stanford.edu gnu.emacs.help:205393 X-Mailman-Approved-At: Thu, 15 May 2014 01:35:46 -0400 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:97658 Archived-At: Hi all, I'd like to run multiple comint sessions of the same type in different buff= ers (e.g. multiple shells, multiple sql connections, etc). I'd like to hit = e.g. M-S for shell, then the single digit for the session ID to either crea= te a new session or switch to the existing session with that ID. The follow= ing code works, but I'm wondering if I can refactor it to eliminate switch-= to-shell and switch-to-sql while still keeping the global-set-key calls sim= ple. In essence, my problem is that I'd like to bind the keys to a function that= interactively elicit arguments (the session #) while also accepting other = preset arguments (the buffer-type and buffer-creation function). The relevant code is included below. Any suggestions on how to simplify thi= s? Thanks! Earl (global-set-key "\M-Q" 'switch-to-sql) (global-set-key "\M-S" 'switch-to-shell) (defun switch-to-shell (buffer-id) (interactive (list (- (read-char-choice (format "Enter id for %s buffer: " 'shell) '(48 49 50 51 52 53 54 55 56 57)) 48))) (message nil) (let ((buffer-type "shell") (buffer-fn 'shell)) (switch-to-interactive-buffer '() buffer-id buffer-type buffer-fn))) (defun switch-to-sql (buffer-id) (interactive (list (- (read-char-choice (format "Enter id for %s buffer: " 'sql) '(48 49 50 51 52 53 54 55 56 57)) 48))) (message nil) (let ((buffer-type "sql") (buffer-fn 'sql-connect-fn)) (switch-to-interactive-buffer '() buffer-id buffer-type buffer-fn))) (defun switch-to-interactive-buffer (buffer-args buffer-id buffer-type buff= er-fn) "Switch to the interactive buffer of the specified ID. ID is elicited from user in minibuffer as a single digit. Looks for buffer type name (e.g. \"shell\") in *interactive-buffer-type*. Looks for buffer creation function (e.g. 'shell) in *interactive-buffer-fn*= . " ;;(message "in buffer-name: %s" (buffer-name)) (let* ((buffer-name (format "*%s-%d*" buffer-type buffer-id)) (buffer (or (get-buffer buffer-name) (let ((new-buffer-args (append buffer-args (list buffe= r-name)))) (apply buffer-fn new-buffer-args))))) ;;(message "switching to buffer %s" buffer) (switch-to-buffer buffer) ;;(message "switched to buffer: %s" (buffer-name)) ))