unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Specifying arguments to interactive functions
@ 2014-05-15  5:20 dont.spam.earl
  2014-05-15  8:04 ` Thien-Thi Nguyen
       [not found] ` <mailman.1382.1400140784.1147.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 5+ messages in thread
From: dont.spam.earl @ 2014-05-15  5:20 UTC (permalink / raw)
  To: help-gnu-emacs

Hi all,

I'd like to run multiple comint sessions of the same type in different buffers (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 create a new session or switch to the existing session with that ID. The following 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 simple.

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 this?

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 buffer-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 buffer-name))))
                       (apply buffer-fn new-buffer-args)))))
    ;;(message "switching to buffer %s" buffer)
    (switch-to-buffer buffer)
    ;;(message "switched to buffer: %s" (buffer-name))
    ))



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Specifying arguments to interactive functions
  2014-05-15  5:20 Specifying arguments to interactive functions dont.spam.earl
@ 2014-05-15  8:04 ` Thien-Thi Nguyen
       [not found] ` <mailman.1382.1400140784.1147.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 5+ messages in thread
From: Thien-Thi Nguyen @ 2014-05-15  8:04 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 830 bytes --]

() dont.spam.earl@gmail.com
() Wed, 14 May 2014 22:20:51 -0700 (PDT)

   Any suggestions on how to simplify this?

                '(48 49 50 51 52 53 54 55 56 57)

These are code points for ASCII "0" through "9", and are already as
simple as possible, in one sense, but not in the "wait six months and
re-grok quickly the code" sense.  Better to be symbolic (not necessarily
w/ Lisp symbols, but rather w/ human-friendly expressions).

For example, you can:
- compress:       (number-sequence 48 57)
- use characters: (number-sequence ?0 ?9)
- go up a level:  (interactive "P") + SMOP

-- 
Thien-Thi Nguyen
   GPG key: 4C807502
   (if you're human and you know it)
      read my lisp: (responsep (questions 'technical)
                               (not (via 'mailing-list)))
                     => nil

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Specifying arguments to interactive functions
       [not found] ` <mailman.1382.1400140784.1147.help-gnu-emacs@gnu.org>
@ 2014-05-15 17:43   ` dont.spam.earl
  2014-05-15 18:06     ` Thien-Thi Nguyen
       [not found]     ` <mailman.1412.1400176929.1147.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 5+ messages in thread
From: dont.spam.earl @ 2014-05-15 17:43 UTC (permalink / raw)
  To: help-gnu-emacs

On Thursday, May 15, 2014 1:04:01 AM UTC-7, Thien-Thi Nguyen wrote:
> () dont.spam.earl@gmail.com
> 
> () Wed, 14 May 2014 22:20:51 -0700 (PDT)
> 
> 
> 
>    Any suggestions on how to simplify this?
> 
> 
> 
>                 '(48 49 50 51 52 53 54 55 56 57)
> 
> 
> 
> These are code points for ASCII "0" through "9", and are already as
> 
> simple as possible, in one sense, but not in the "wait six months and
> 
> re-grok quickly the code" sense.  Better to be symbolic (not necessarily
> 
> w/ Lisp symbols, but rather w/ human-friendly expressions).
> 
> 
> 
> For example, you can:
> 
> - compress:       (number-sequence 48 57)
> 
> - use characters: (number-sequence ?0 ?9)
> 
> - go up a level:  (interactive "P") + SMOP
> 
> 
> 
> -- 
> 
> Thien-Thi Nguyen
> 
>    GPG key: 4C807502
> 
>    (if you're human and you know it)
> 
>       read my lisp: (responsep (questions 'technical)
> 
>                                (not (via 'mailing-list)))
> 
>                      => nil

Thanks. Any tips on passing an argument to 'switch-to-interactive-buffer while having it still call 'interactive to get the digit from the user?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Specifying arguments to interactive functions
  2014-05-15 17:43   ` dont.spam.earl
@ 2014-05-15 18:06     ` Thien-Thi Nguyen
       [not found]     ` <mailman.1412.1400176929.1147.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 5+ messages in thread
From: Thien-Thi Nguyen @ 2014-05-15 18:06 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 675 bytes --]

() dont.spam.earl@gmail.com
() Thu, 15 May 2014 10:43:56 -0700 (PDT)

   Any tips on passing an argument to 'switch-to-interactive-buffer
   while having it still call 'interactive to get the digit from the
   user?

First, ‘C-h f interactive’ and also (info "(elisp) Using Interactive").
Next, experiment.  Next, read some source.  Next, post questions on the
discrepencies and lacunae you might (think you) experience.  That's it.

-- 
Thien-Thi Nguyen
   GPG key: 4C807502
   (if you're human and you know it)
      read my lisp: (responsep (questions 'technical)
                               (not (via 'mailing-list)))
                     => nil

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Specifying arguments to interactive functions
       [not found]     ` <mailman.1412.1400176929.1147.help-gnu-emacs@gnu.org>
@ 2014-05-18 17:07       ` dont.spam.earl
  0 siblings, 0 replies; 5+ messages in thread
From: dont.spam.earl @ 2014-05-18 17:07 UTC (permalink / raw)
  To: help-gnu-emacs

On Thursday, May 15, 2014 11:06:24 AM UTC-7, Thien-Thi Nguyen wrote:

> 
> First, 'C-h f interactive' and also (info "(elisp) Using Interactive").
> 
> Next, experiment.  Next, read some source.  Next, post questions on the
> 
> discrepencies and lacunae you might (think you) experience.  That's it.


Well, even after looking at the docs, I'm still looking for an answer to the same question: Is there a way to call interactive to elicit only _some_ of the arguments of a function.

Alternately, if there's a standard workaround for this, I'd be interested in that too.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-05-18 17:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-15  5:20 Specifying arguments to interactive functions dont.spam.earl
2014-05-15  8:04 ` Thien-Thi Nguyen
     [not found] ` <mailman.1382.1400140784.1147.help-gnu-emacs@gnu.org>
2014-05-15 17:43   ` dont.spam.earl
2014-05-15 18:06     ` Thien-Thi Nguyen
     [not found]     ` <mailman.1412.1400176929.1147.help-gnu-emacs@gnu.org>
2014-05-18 17:07       ` dont.spam.earl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).