* What's wrong with this lisp code in my init file?! @ 2006-12-31 16:15 Endless Story 2006-12-31 18:48 ` Eric Hanchrow [not found] ` <mailman.2592.1167591202.2155.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 8+ messages in thread From: Endless Story @ 2006-12-31 16:15 UTC (permalink / raw) On XP, I'm running both the Windows build of Emacs and the Cywgin console version of Emacs. I don't really need both, but I like having Emacs available in the Cygwin environment. I've installed Ghostview to be able to print to my non-postscript Printer. But now I'm running into a wierd problem. I have lisp code that should be restricting the correct printing commands based on the variable window-system - but when I run the Windows build of Emacs, it complains that it can't find /cygdrive/c/Program/Files/Ghostgum/gsview/gsprint.exe! If I comment out that line it goes ahead and prints using its own section of the code. So why is this problem occurring? On the console side, it doesn't care if the Windows code is in there. Here's the relevant code: (setq printer-name "//BREATH-000/Randy's HP 1200") (setq ps-printer-name t) (if (eq window-system 'w32) (setq ps-lpr-command "c:/Program Files/Ghostgum/gsview/gsprint.exe")) ;; note that for printing via console, the order of statements matters - ;; must set printer name before issuing print command! (if (eq window-system nil) (setq ps-printer-name t) (setq ps-lpr-command "/cygdrive/c/Program Files/Ghostgum/gsview/gsprint.exe")) ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: What's wrong with this lisp code in my init file?! 2006-12-31 16:15 What's wrong with this lisp code in my init file?! Endless Story @ 2006-12-31 18:48 ` Eric Hanchrow [not found] ` <mailman.2592.1167591202.2155.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 8+ messages in thread From: Eric Hanchrow @ 2006-12-31 18:48 UTC (permalink / raw) Try this instead: (setq printer-name "//BREATH-000/Randy's HP 1200") (setq ps-printer-name t) ;; must set printer name before issuing print command! (setq ps-lpr-command (if (eq window-system 'w32) "c:/Program Files/Ghostgum/gsview/gsprint.exe" "/cygdrive/c/Program Files/Ghostgum/gsview/gsprint.exe")) If that works, as I expect it will, your problem was that you've got two clauses in your second "if" statement. Clearly you're expecting them to both get evaluated when window-system is nil. But because of the way "if" works, only the first gets evaluated; the second gets evaluated only when window-system is _not_ nil. If you had used Emacs' lisp indentation on your code, you might have noticed this yourself, since it will show the two clauses indented different amounts. -- ハ ハ ミ^・^ミ `~~~´ ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <mailman.2592.1167591202.2155.help-gnu-emacs@gnu.org>]
* Re: What's wrong with this lisp code in my init file?! [not found] ` <mailman.2592.1167591202.2155.help-gnu-emacs@gnu.org> @ 2006-12-31 19:57 ` Endless Story 2006-12-31 21:51 ` Eric Hanchrow [not found] ` <mailman.2595.1167601997.2155.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 8+ messages in thread From: Endless Story @ 2006-12-31 19:57 UTC (permalink / raw) Thanks - I've been thinking the problem was something like that. However it doesn't work to print within Cygwin! Why not? Well, for whatever reason, I find that the gsprint command within Cygwin won't work unless I issue two commands in a row: first, "setq ps-printer-name t", and then the gsprint.exe command. I have no idea why that is, but issuing the printer name command prior to and outside of the "if" clause doesn't get the job done. Boy, that doesn't seem right to me, but there it is. So I've been trying to figure out how to package the two commands together within the if clause. Eric Hanchrow wrote: > Try this instead: > > (setq printer-name "//BREATH-000/Randy's HP 1200") > (setq ps-printer-name t) > > ;; must set printer name before issuing print command! > (setq ps-lpr-command > (if (eq window-system 'w32) > "c:/Program Files/Ghostgum/gsview/gsprint.exe" > "/cygdrive/c/Program Files/Ghostgum/gsview/gsprint.exe")) > > If that works, as I expect it will, your problem was that you've got > two clauses in your second "if" statement. Clearly you're expecting > them to both get evaluated when window-system is nil. But because of > the way "if" works, only the first gets evaluated; the second gets > evaluated only when window-system is _not_ nil. > > If you had used Emacs' lisp indentation on your code, you might have > noticed this yourself, since it will show the two clauses indented > different amounts. > > -- > > ハ ハ > ミ^・^ミ > `~~~´ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: What's wrong with this lisp code in my init file?! 2006-12-31 19:57 ` Endless Story @ 2006-12-31 21:51 ` Eric Hanchrow 2006-12-31 22:29 ` Drew Adams [not found] ` <mailman.2595.1167601997.2155.help-gnu-emacs@gnu.org> 1 sibling, 1 reply; 8+ messages in thread From: Eric Hanchrow @ 2006-12-31 21:51 UTC (permalink / raw) >>>>> "Endless" == Endless Story <usable.thought@gmail.com> writes: Endless> So I've been trying to figure out how to package the two Endless> commands together within the if clause. Well, that's easy enough: (setq printer-name "//BREATH-000/Randy's HP 1200") ;; must set printer name before issuing print command! (if (eq window-system 'w32) (setq ps-printer-name t ps-lpr-command "c:/Program Files/Ghostgum/gsview/gsprint.exe") (setq ps-printer-name t ps-lpr-command "/cygdrive/c/Program Files/Ghostgum/gsview/gsprint.exe")) That's because "setq" lets you set any number of variables at once. But there's an even more general way to do more than one thing inside an "if": the "progn" form. It simply does a bunch of things one after the other: (if (furryp critter) ;; yup, furry (progn (pet critter) (comb-fur critter)) ;; no fur (progn (apply 'sunscreen critter) (search-for-tattoos critter))) :: And by the way -- I haven't checked to see if this is the case, but I suspect you can use "c:/Program Files/Ghostgum/gsview/gsprint.exe" for both Cygwin _and_ non-cygwin versions. Cygwin programs in general do the right thing with file names that start with a drive letter and colon. -- 'The energy capacity of batteries is increasing 5 percent to 8 percent annually, but demand is increasing exponentially,' Mr. Cooper said. -- New York Times ^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: What's wrong with this lisp code in my init file?! 2006-12-31 21:51 ` Eric Hanchrow @ 2006-12-31 22:29 ` Drew Adams 0 siblings, 0 replies; 8+ messages in thread From: Drew Adams @ 2006-12-31 22:29 UTC (permalink / raw) > But there's an even more general way to do more than one thing inside > an "if": the "progn" form. It simply does a bunch of things one after > the other: > > (if (furryp critter) > > ;; yup, furry > (progn > (pet critter) > (comb-fur critter)) > > ;; no fur > (progn > (apply 'sunscreen critter) > (search-for-tattoos critter))) (The second `progn' is not needed, there, BTW. `if' has an implicit `progn' for the false branch. I know that Eric knows that, but I thought I'd point it out.) While we're on the subject of conditionals and `progn', and hoping not to open too big a can of worms... `cond' is very general. Each of its clauses has in implicit `progn'. In this case, the code would be: (cond ((furryp critter) (pet critter) (comb-fur critter)) (t (apply 'sunscreen critter) (search-for-tattoos critter))) However, if there is only one test, and the conditional clause is used only for effect, not also for the value it returns, then many people (myself included) prefer to use `when' or `unless', instead of `if' or `cond'. This is largely a convention for human readers, letting them know that the value is unimportant. Like `cond' and `if' (second branch), `when' and `unless' have an implicit `progn'. In the OP case, the code would be: (when (eq window-system 'w32) (setq ps-printer-name t) (setq ps-lpr-command "...")) Of course, as Eric pointed out, in this case, you can combine the setq's: (when (eq window-system 'w32) (setq ps-printer-name t ps-lpr-command "...")) And there are also `and' and `or', which are sometimes used for nested conditionals of a particular form, and where the value matters. For example, this: (if a a (if b b (if c c nil))) is often written like this: (or a b c). And this: (if a (if b (if c c nil) nil) nil) is often written like this: (and a b c). If the value is unimportant, some people will combine `when' or `unless' with `and' or `or'. That is, instead of this: (and a b c (do-it-to-it)) Some people will write this: (when (and a b c) (do-it-to-it)) Most of choosing a particular conditional to use is about communicating intention to (human) readers of your code. Among various choices that do essentially the same thing, some are sometimes more readable than others or more clearly indicate what is important. ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <mailman.2595.1167601997.2155.help-gnu-emacs@gnu.org>]
* Re: What's wrong with this lisp code in my init file?! [not found] ` <mailman.2595.1167601997.2155.help-gnu-emacs@gnu.org> @ 2006-12-31 22:16 ` Harald Hanche-Olsen 2006-12-31 22:50 ` Drew Adams [not found] ` <mailman.2599.1167605423.2155.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 8+ messages in thread From: Harald Hanche-Olsen @ 2006-12-31 22:16 UTC (permalink / raw) + Eric Hanchrow <offby1@blarg.net>: | But there's an even more general way to do more than one thing inside | an "if": the "progn" form. It simply does a bunch of things one after | the other: And of course, there is cond: (cond ((eq window-system 'w32) (setq ps-printer-name t) (setq ps-lpr-command "c:/Program Files/Ghostgum/gsview/gsprint.exe")) ((eq window-system nil) (setq ps-printer-name t) (setq ps-lpr-command "/cygdrive/c/Program Files/Ghostgum/gsview/gsprint.exe"))) And then there are when and unless in the cl package: (require 'cl) (when (eq window-system 'w32) (setq ps-printer-name t) (setq ps-lpr-command "c:/Program Files/Ghostgum/gsview/gsprint.exe")) (unless window-system (setq ps-printer-name t) (setq ps-lpr-command "/cygdrive/c/Program Files/Ghostgum/gsview/gsprint.exe")) -- * Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/> - It is undesirable to believe a proposition when there is no ground whatsoever for supposing it is true. -- Bertrand Russell ^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: What's wrong with this lisp code in my init file?! 2006-12-31 22:16 ` Harald Hanche-Olsen @ 2006-12-31 22:50 ` Drew Adams [not found] ` <mailman.2599.1167605423.2155.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 8+ messages in thread From: Drew Adams @ 2006-12-31 22:50 UTC (permalink / raw) Great minds think alike, as they say ;-). Just one thing to point out: > And then there are when and unless in the cl package: > (require 'cl) Since Emacs 20, you no longer need to require `cl' for this. `when' and `unless' are defined in preloaded Emacs-Lisp library `subr.el'. ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <mailman.2599.1167605423.2155.help-gnu-emacs@gnu.org>]
* Re: What's wrong with this lisp code in my init file?! [not found] ` <mailman.2599.1167605423.2155.help-gnu-emacs@gnu.org> @ 2007-01-01 1:48 ` Endless Story 0 siblings, 0 replies; 8+ messages in thread From: Endless Story @ 2007-01-01 1:48 UTC (permalink / raw) I love all this lisp stuff. I left my Gnu Emacs LISP book (paid-for version) at a different house, but I may go ahead and print out the PS version from the Web. However, solving my problem turned out to be much simpler, basically because of a dumb error. After some fumbling around I realized that the Cygwin setup just needs - (setq printer-name "//defuse/Printer2") (setq ps-printer-name t) - for postscript printing, and doesn't need to call to gsprint - some kind of postscript translation is already built into Cygwin. So my total code snippet that keeps both Windows Emacs and Cygwin console Emacs happy looks like this: (setq printer-name "//defuse/Printer2") (setq ps-printer-name t) (if (eq window-system 'w32) (setq ps-lpr-command "c:/Program Files/Ghostgum/gsview/gsprint.exe")) ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2007-01-01 1:48 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-12-31 16:15 What's wrong with this lisp code in my init file?! Endless Story 2006-12-31 18:48 ` Eric Hanchrow [not found] ` <mailman.2592.1167591202.2155.help-gnu-emacs@gnu.org> 2006-12-31 19:57 ` Endless Story 2006-12-31 21:51 ` Eric Hanchrow 2006-12-31 22:29 ` Drew Adams [not found] ` <mailman.2595.1167601997.2155.help-gnu-emacs@gnu.org> 2006-12-31 22:16 ` Harald Hanche-Olsen 2006-12-31 22:50 ` Drew Adams [not found] ` <mailman.2599.1167605423.2155.help-gnu-emacs@gnu.org> 2007-01-01 1:48 ` Endless Story
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).