all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* using variable names as args to interactive functions
@ 2008-01-12  0:53 Stuart
  2008-01-12  2:09 ` Pascal Bourguignon
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Stuart @ 2008-01-12  0:53 UTC (permalink / raw)
  To: help-gnu-emacs

I have some variables which I set at startup with setq. There are a
bunch of variables that get set. Each is a string representing a
directory path. I want a function which I can just type the variable
name and it opens dired with that directory.

However, this doesn't work because the interactive option "v" doesn't
include the variables set with setq because this requires that: "A
variable declared to be a user option (i.e., satisfying the predicate
user-variable-p)."

Any ideas? Thanks.

(defun find-my-special-dir (dir)
	(interactive "vSpecial dir: ")
	(find-file dir))


Example
--------------
startup:
     (setq my-special-dir-a "/path/to/my/special/dir")

minibuffer:
     Special dir: my-special-dir-a

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

* Re: using variable names as args to interactive functions
  2008-01-12  0:53 using variable names as args to interactive functions Stuart
@ 2008-01-12  2:09 ` Pascal Bourguignon
  2008-01-12  3:28 ` Daniel Pittman
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Pascal Bourguignon @ 2008-01-12  2:09 UTC (permalink / raw)
  To: help-gnu-emacs

Stuart <stuart.tett@gmail.com> writes:
> I have some variables which I set at startup with setq. There are a
> bunch of variables that get set. Each is a string representing a
> directory path. I want a function which I can just type the variable
> name and it opens dired with that directory.
>
> However, this doesn't work because the interactive option "v" doesn't
> include the variables set with setq because this requires that: "A
> variable declared to be a user option (i.e., satisfying the predicate
> user-variable-p)."
>
> Any ideas? Thanks.
>
> (defun find-my-special-dir (dir)
> 	(interactive "vSpecial dir: ")
> 	(find-file dir))

Ask for a random expression:

(defun test (dir)
 (interactive "XExpression: ")
 (message (format "Got %S" dir)))

   M-x test RET
   (concat (first load-path) "/toto") RET

Gives:

   Got "/home/pjb/src/public/emacs//toto"

(my (first load-path) is "/home/pjb/src/public/emacs/").

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"Debugging?  Klingons do not debug! Our software does not coddle the
weak."

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

* Re: using variable names as args to interactive functions
  2008-01-12  0:53 using variable names as args to interactive functions Stuart
  2008-01-12  2:09 ` Pascal Bourguignon
@ 2008-01-12  3:28 ` Daniel Pittman
  2008-01-13  8:40 ` Mathias Dahl
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Daniel Pittman @ 2008-01-12  3:28 UTC (permalink / raw)
  To: help-gnu-emacs

Stuart <stuart.tett@gmail.com> writes:

> I have some variables which I set at startup with setq. There are a
> bunch of variables that get set. Each is a string representing a
> directory path. I want a function which I can just type the variable
> name and it opens dired with that directory.

You might find it easier to define your paths in the environment, either
before starting Emacs or using `setenv'.

You can then use `find-file' with the environment variable to open
dired, such as:

    M-: (setenv "MYDIR" "/home/daniel/example") ret
    C-x C-f $MYDIR ret

That should open up /home/daniel/example in dired for you.

This substitution works as expected everywhere, too, so you can open
$MYDIR/foobar and have it open a file under that directory...

Regards,
        Daniel
-- 
Daniel Pittman <daniel@cybersource.com.au>           Phone: 03 9428 6922
1/130-132 Stawell St, Richmond              Web: http://www.cyber.com.au
Cybersource: Australia's Leading Linux and Open Source Solutions Company

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

* Re: using variable names as args to interactive functions
  2008-01-12  0:53 using variable names as args to interactive functions Stuart
  2008-01-12  2:09 ` Pascal Bourguignon
  2008-01-12  3:28 ` Daniel Pittman
@ 2008-01-13  8:40 ` Mathias Dahl
  2008-01-15  3:17 ` Kevin Rodgers
  2008-01-16  1:42 ` Stuart
  4 siblings, 0 replies; 7+ messages in thread
From: Mathias Dahl @ 2008-01-13  8:40 UTC (permalink / raw)
  To: help-gnu-emacs

Stuart <stuart.tett@gmail.com> writes:

> I have some variables which I set at startup with setq. There are a
> bunch of variables that get set. Each is a string representing a
> directory path. I want a function which I can just type the variable
> name and it opens dired with that directory.

Just in case you did not know about it, have you looked at Emacs'
bookmark facility? It saves "places" under names you define and you can
easily jump to them later. Directories are supported.

The only thing I am missing from them is that you cannot use them (I
think) in `find-file'. I often do C-x C-f only to remember that I have a
bookmark for what I was going to find. And even if I do remember that I
have a bookmark there are times when other command asks me for a
directory or file and where using a bookmark would have been
useful. Anyone know a solution to this?

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

* Re: using variable names as args to interactive functions
  2008-01-12  0:53 using variable names as args to interactive functions Stuart
                   ` (2 preceding siblings ...)
  2008-01-13  8:40 ` Mathias Dahl
@ 2008-01-15  3:17 ` Kevin Rodgers
  2008-01-16  1:42 ` Stuart
  4 siblings, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2008-01-15  3:17 UTC (permalink / raw)
  To: help-gnu-emacs

Stuart wrote:
> I have some variables which I set at startup with setq. There are a
> bunch of variables that get set. Each is a string representing a
> directory path. I want a function which I can just type the variable
> name and it opens dired with that directory.
> 
> However, this doesn't work because the interactive option "v" doesn't
> include the variables set with setq because this requires that: "A
> variable declared to be a user option (i.e., satisfying the predicate
> user-variable-p)."
> 
> Any ideas? Thanks.
> 
> (defun find-my-special-dir (dir)
> 	(interactive "vSpecial dir: ")
> 	(find-file dir))
> 
> 
> Example
> --------------
> startup:
>      (setq my-special-dir-a "/path/to/my/special/dir")
> 
> minibuffer:
>      Special dir: my-special-dir-a

,----[ C-h f user-variable-p RET ]
| user-variable-p is a built-in function in `C source code'.
| (user-variable-p variable)
|
| Return t if variable is intended to be set and modified by users.
| (The alternative is a variable used internally in a Lisp program.)
| A variable is a user variable if
| (1) the first character of its documentation is `*', or
| (2) it is customizable (its property list contains a non-nil value
|     of `standard-value' or `custom-autoload'), or
| (3) it is an alias for another user variable.
| Return nil if variable is an alias and there is a loop in the
| chain of symbols.
|
| [back]
`----

So:

(defvar my-special-dir-a "/path/to/my/special/dir"
   "*Special directory `a'.")

-- 
Kevin Rodgers
Denver, Colorado, USA

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

* Re: using variable names as args to interactive functions
  2008-01-12  0:53 using variable names as args to interactive functions Stuart
                   ` (3 preceding siblings ...)
  2008-01-15  3:17 ` Kevin Rodgers
@ 2008-01-16  1:42 ` Stuart
  2008-01-16  3:01   ` Kevin Rodgers
  4 siblings, 1 reply; 7+ messages in thread
From: Stuart @ 2008-01-16  1:42 UTC (permalink / raw)
  To: help-gnu-emacs

Here's what I ended up doing:

First I changed all the my script to generate the variables as
defvar's instead of setq's:
  (defvar my-special-dir-a "/path/to/my/special/dir" "*Special
directory `a'.")

This allows the "*" to make it a user variable so it can be read by
the interactive prompt.

Now my definition looks like this:

(defun find-my-special-dir (dir)
	(interactive "vSpecial Directory: ")
	(find-file (symbol-value (symbol-value 'dir))))

symbol-value 'dir returns the name of the variable the user types at
the prompt (i.e., my-special-dir-a)
Then the symbol-value on top of that returns the string "/path/to/my/
special/dir" and now it works!

Thanks!

On Jan 11, 4:53 pm, Stuart <stuart.t...@gmail.com> wrote:
> I have some variables which I set at startup with setq. There are a
> bunch of variables that get set. Each is a string representing a
> directory path. I want a function which I can just type the variable
> name and it opens dired with that directory.
>
> However, this doesn't work because the interactive option "v" doesn't
> include the variables set with setq because this requires that: "A
> variable declared to be a user option (i.e., satisfying the predicate
> user-variable-p)."
>
> Any ideas? Thanks.
>
> (defun find-my-special-dir (dir)
>         (interactive "vSpecial dir: ")
>         (find-file dir))
>
> Example
> --------------
> startup:
>      (setq my-special-dir-a "/path/to/my/special/dir")
>
> minibuffer:
>      Special dir: my-special-dir-a

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

* Re: using variable names as args to interactive functions
  2008-01-16  1:42 ` Stuart
@ 2008-01-16  3:01   ` Kevin Rodgers
  0 siblings, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2008-01-16  3:01 UTC (permalink / raw)
  To: help-gnu-emacs

Stuart wrote:
> Here's what I ended up doing:
> 
> First I changed all the my script to generate the variables as
> defvar's instead of setq's:
>   (defvar my-special-dir-a "/path/to/my/special/dir" "*Special
> directory `a'.")
> 
> This allows the "*" to make it a user variable so it can be read by
> the interactive prompt.
> 
> Now my definition looks like this:
> 
> (defun find-my-special-dir (dir)
> 	(interactive "vSpecial Directory: ")
> 	(find-file (symbol-value (symbol-value 'dir))))
> 
> symbol-value 'dir returns the name of the variable the user types at
> the prompt (i.e., my-special-dir-a)
> Then the symbol-value on top of that returns the string "/path/to/my/
> special/dir" and now it works!

(find-file (symbol-value dir)) ; dir should be renamed dir-sym

-- 
Kevin Rodgers
Denver, Colorado, USA

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

end of thread, other threads:[~2008-01-16  3:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-12  0:53 using variable names as args to interactive functions Stuart
2008-01-12  2:09 ` Pascal Bourguignon
2008-01-12  3:28 ` Daniel Pittman
2008-01-13  8:40 ` Mathias Dahl
2008-01-15  3:17 ` Kevin Rodgers
2008-01-16  1:42 ` Stuart
2008-01-16  3:01   ` Kevin Rodgers

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.