unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Windows port: using Windows' default printer
@ 2003-02-20 13:18 Peter 'Luna' Runestig
  2003-02-20 23:05 ` Jason Rumney
  0 siblings, 1 reply; 25+ messages in thread
From: Peter 'Luna' Runestig @ 2003-02-20 13:18 UTC (permalink / raw)


Hi all,

I've had a patch lying around for a while, that adds two lisp variables:
'w32-default-printer-device' and
'w32-printer-name-follows-default-device'. 'w32-default-printer-device'
  contains Windows' default printer's device name, which is either the
printer port name (for locally connected printers), or an UNC path (for
remote printers). You can then have something like this in .emacs:
(setq printer-name w32-default-printer-device)

If 'w32-printer-name-follows-default-device' is set to 't',
'printer-name' is updated, if you change the default printer while emacs
is running.

I mentioned this patch on bug-gnu-emacs@gnu.org almost a year ago, but I
now realize that this probably is a more appropriate forum, so I just
thought I'll mention it here. The link:
ftp://ftp.runestig.com/pub/emacs/emacs-20030219-w32-default-printer-device.patch
http://ftp.runestig.com/pub/emacs/emacs-20030219-w32-default-printer-device.patch

Cheers,
- Peter
-- 
Peter 'Luna' Runestig (fd. Altberg), Sweden <peter@runestig.com>
PGP Key ID: 0xD07BBE13
Fingerprint: 7B5C 1F48 2997 C061 DE4B  42EA CB99 A35C D07B BE13
AOL Instant Messenger Screen name: PRunestig

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

* Re: Windows port: using Windows' default printer
  2003-02-20 13:18 Windows port: using Windows' default printer Peter 'Luna' Runestig
@ 2003-02-20 23:05 ` Jason Rumney
  2003-02-21  6:52   ` Peter 'Luna' Runestig
  0 siblings, 1 reply; 25+ messages in thread
From: Jason Rumney @ 2003-02-20 23:05 UTC (permalink / raw)
  Cc: emacs-devel

"Peter 'Luna' Runestig" <peter+emacs@runestig.com> writes:

> Hi all,
> 
> I've had a patch lying around for a while, that adds two lisp variables:
> 'w32-default-printer-device' and
> 'w32-printer-name-follows-default-device'.

Thank you. I do still have your original mail in my to-look-at list,
it has not been forgotten completely.

I wonder whether it is really necessary to add two new user variables
to get this functionality.  We already have `printer-name', perhaps
setting it to nil should select the system's default printer, as it
does on other systems. In general we want to avoid introducing new
variables, especially OS specific ones.

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

* Re: Windows port: using Windows' default printer
  2003-02-20 23:05 ` Jason Rumney
@ 2003-02-21  6:52   ` Peter 'Luna' Runestig
  2003-02-21  8:20     ` Jason Rumney
  0 siblings, 1 reply; 25+ messages in thread
From: Peter 'Luna' Runestig @ 2003-02-21  6:52 UTC (permalink / raw)
  Cc: emacs-devel

On 2003-02-21 00:05, Jason Rumney wrote:
> I wonder whether it is really necessary to add two new user variables
> to get this functionality.  We already have `printer-name', perhaps
> setting it to nil should select the system's default printer, as it
> does on other systems. In general we want to avoid introducing new
> variables, especially OS specific ones.

OK. Sure, I don't know much about how you prefer things. I did it like
this because I wanted to leave as much as possible untouched. So, you
want it like, if `printer-name' is nil on startup, `printer-name' should
follow the device name of Windows default printer?

-- 
Peter 'Luna' Runestig (fd. Altberg), Sweden <peter@runestig.com>
PGP Key ID: 0xD07BBE13
Fingerprint: 7B5C 1F48 2997 C061 DE4B  42EA CB99 A35C D07B BE13
AOL Instant Messenger Screen name: PRunestig

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

* Re: Windows port: using Windows' default printer
  2003-02-21  6:52   ` Peter 'Luna' Runestig
@ 2003-02-21  8:20     ` Jason Rumney
  2003-09-12 19:34       ` Peter 'Luna' Runestig
  0 siblings, 1 reply; 25+ messages in thread
From: Jason Rumney @ 2003-02-21  8:20 UTC (permalink / raw)
  Cc: emacs-devel

"Peter 'Luna' Runestig" <peter@runestig.com> writes:

> On 2003-02-21 00:05, Jason Rumney wrote:
> > I wonder whether it is really necessary to add two new user variables
> > to get this functionality.  We already have `printer-name', perhaps
> > setting it to nil should select the system's default printer, as it
> > does on other systems. In general we want to avoid introducing new
> > variables, especially OS specific ones.
> 
> OK. Sure, I don't know much about how you prefer things. I did it like
> this because I wanted to leave as much as possible untouched. So, you
> want it like, if `printer-name' is nil on startup, `printer-name' should
> follow the device name of Windows default printer?

If it is nil whenever it is used, it should act like that. So even if
it is non-nil at startup, the user should be able to set it to nil to
use the default printer.

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

* Re: Windows port: using Windows' default printer
  2003-02-21  8:20     ` Jason Rumney
@ 2003-09-12 19:34       ` Peter 'Luna' Runestig
  2003-09-13 10:04         ` Eli Zaretskii
  2003-09-15 14:52         ` Stefan Monnier
  0 siblings, 2 replies; 25+ messages in thread
From: Peter 'Luna' Runestig @ 2003-09-12 19:34 UTC (permalink / raw)


Hi all!

This is a reworked version of the `w32-default-printer-device' variable
patch I posted in March 2002. After a private mail exchange with Jason
Rumney, I followed his ideas, and instead implemented a
`default-printer-name' function, that is to be used if `printer-name'
is nil. I quote Jason's description of the idea:

>>>>>>
[...] Rather, you should expose a function to lisp (using the DEFUN C
macro) which returns the default printer name, then modify the code that
uses printer-name (and ps-printer-name) to call this function if
printer-name is nil and the function is available.

If possible, avoid w32- specific variables, function names and tests,
then if MacOS or other systems need to do a similar thing, they just
need to implement a function of the same name. This is much cleaner than
having branches all over the place to handle specific platforms.

An example of the Lisp required to do what I'm thinking of would be:

    (let ((printer-name (or printer-name 
                            (and (fboundp 'default-printer-name)
                                 (default-printer-name)))))
       ;; Code that uses printer-name here
      )
<<<<<<


diff -bur emacs-cvs-20030904.orig/lisp/ChangeLog emacs-cvs-20030904/lisp/ChangeLog
--- emacs-cvs-20030904.orig/lisp/ChangeLog	2003-09-03 10:14:52.000000000 +0200
+++ emacs-cvs-20030904/lisp/ChangeLog	2003-09-08 09:01:53.000000000 +0200
@@ -1,3 +1,8 @@
+2003-09-05  Peter Runestig <peter@runestig.com>
+
+	* dos-w32.el, lpr.el, ps-print.el, play/handwrite.el: Added support for
+	the `default-printer-name' function.
+
 2003-09-02  Jason Rumney  <jasonr@gnu.org>
 
 	* international/titdic-cnv.el (tsang-quick-converter): Fix broken
diff -bur emacs-cvs-20030904.orig/lisp/dos-w32.el emacs-cvs-20030904/lisp/dos-w32.el
--- emacs-cvs-20030904.orig/lisp/dos-w32.el	2003-09-03 10:14:55.000000000 +0200
+++ emacs-cvs-20030904/lisp/dos-w32.el	2003-09-05 22:50:41.000000000 +0200
@@ -378,7 +378,9 @@
 	 (printer (or (and (boundp 'dos-printer)
 			   (stringp (symbol-value 'dos-printer))
 			   (symbol-value 'dos-printer))
-		      printer-name)))
+		      printer-name
+		      (and (fboundp 'default-printer-name)
+			   (default-printer-name)))))
     (or (eq coding-system-for-write 'no-conversion)
 	(setq coding-system-for-write
 	      (aref eol-type 1)))	; force conversion to DOS EOLs
@@ -411,7 +413,9 @@
   (let ((printer (or (and (boundp 'dos-ps-printer)
 			  (stringp (symbol-value 'dos-ps-printer))
 			  (symbol-value 'dos-ps-printer))
-		     ps-printer-name)))
+		     ps-printer-name
+		     (and (fboundp 'default-printer-name)
+			  (default-printer-name)))))
     (direct-print-region-helper printer start end lpr-prog
 				delete-text buf display rest)))
 
diff -bur emacs-cvs-20030904.orig/lisp/lpr.el emacs-cvs-20030904/lisp/lpr.el
--- emacs-cvs-20030904.orig/lisp/lpr.el	2003-09-03 10:14:58.000000000 +0200
+++ emacs-cvs-20030904/lisp/lpr.el	2003-09-05 22:50:41.000000000 +0200
@@ -255,9 +255,12 @@
 		    ;; These belong in pr if we are using that.
 		    (and lpr-add-switches lpr-headers-switches
 			 (list "-T" title))
-		    (and (stringp printer-name)
+		    (or (and (stringp printer-name)
 			 (list (concat lpr-printer-switch
 				       printer-name)))
+			(and (fboundp 'default-printer-name)
+			     (list (concat lpr-printer-switch
+					   (default-printer-name)))))
 		    nswitches))
       (if (markerp end)
 	  (set-marker end nil))
diff -bur emacs-cvs-20030904.orig/lisp/play/handwrite.el emacs-cvs-20030904/lisp/play/handwrite.el
--- emacs-cvs-20030904.orig/lisp/play/handwrite.el	2003-09-03 10:15:15.000000000 +0200
+++ emacs-cvs-20030904/lisp/play/handwrite.el	2003-09-05 22:50:41.000000000 +0200
@@ -335,7 +335,9 @@
 	  (let* ((coding-system-for-write 'raw-text-unix)
 		 (ps-printer-name (or ps-printer-name
 				      (and (boundp 'printer-name)
-					   printer-name)))
+					   printer-name)
+				      (and (fboundp 'default-printer-name)
+					   (default-printer-name))))
 		 (ps-lpr-switches
 		  (if (stringp ps-printer-name)
 		      (list (concat "-P" ps-printer-name)))))
diff -bur emacs-cvs-20030904.orig/lisp/ps-print.el emacs-cvs-20030904/lisp/ps-print.el
--- emacs-cvs-20030904.orig/lisp/ps-print.el	2003-09-03 10:15:00.000000000 +0200
+++ emacs-cvs-20030904/lisp/ps-print.el	2003-09-05 22:50:41.000000000 +0200
@@ -6563,7 +6563,9 @@
 	(let* ((coding-system-for-write 'raw-text-unix)
 	       (ps-printer-name (or ps-printer-name
 				    (and (boundp 'printer-name)
-					 (symbol-value 'printer-name))))
+					 (symbol-value 'printer-name))
+				    (and (fboundp 'default-printer-name)
+					 (default-printer-name))))
 	       (ps-lpr-switches
 		(append ps-lpr-switches
 			(and (stringp ps-printer-name)
diff -bur emacs-cvs-20030904.orig/nt/ChangeLog emacs-cvs-20030904/nt/ChangeLog
--- emacs-cvs-20030904.orig/nt/ChangeLog	2003-09-04 09:19:35.000000000 +0200
+++ emacs-cvs-20030904/nt/ChangeLog	2003-09-08 09:04:42.000000000 +0200
@@ -1,3 +1,7 @@
+2003-09-05  Peter Runestig <peter@runestig.com>
+
+	* gmake.defs, nmake.defs: Add linking to ``winspool.lib''.
+
 2003-09-03  Peter Runestig <peter@runestig.com>
 
 	* configure.bat: Create ``makefile'' in directories man, lispref
diff -bur emacs-cvs-20030904.orig/nt/gmake.defs emacs-cvs-20030904/nt/gmake.defs
--- emacs-cvs-20030904.orig/nt/gmake.defs	2003-09-03 10:15:31.000000000 +0200
+++ emacs-cvs-20030904/nt/gmake.defs	2003-09-05 22:50:41.000000000 +0200
@@ -177,6 +177,7 @@
 USER32		= -luser32
 WSOCK32		= -lwsock32
 WINMM     = -lwinmm
+WINSPOOL	= -lwinspool
 
 ifdef NOOPT
 DEBUG_CFLAGS	= -DEMACSDEBUG
diff -bur emacs-cvs-20030904.orig/nt/nmake.defs emacs-cvs-20030904/nt/nmake.defs
--- emacs-cvs-20030904.orig/nt/nmake.defs	2003-09-03 10:15:31.000000000 +0200
+++ emacs-cvs-20030904/nt/nmake.defs	2003-09-05 22:50:41.000000000 +0200
@@ -124,6 +124,7 @@
 USER32		= user32.lib
 WSOCK32		= wsock32.lib
 WINMM     = winmm.lib
+WINSPOOL	= winspool.lib
 
 !ifdef NOOPT
 DEBUG_CFLAGS	= -DEMACSDEBUG
diff -bur emacs-cvs-20030904.orig/src/ChangeLog emacs-cvs-20030904/src/ChangeLog
--- emacs-cvs-20030904.orig/src/ChangeLog	2003-09-03 10:15:33.000000000 +0200
+++ emacs-cvs-20030904/src/ChangeLog	2003-09-08 09:06:20.000000000 +0200
@@ -1,3 +1,7 @@
+2003-09-05  Peter Runestig <peter@runestig.com>
+
+	* makefile.w32-in, w32fns.c: Add `default-printer-name' function.
+
 2003-09-03  Kim F. Storm  <storm@cua.dk>
 
 	* xdisp.c (get_window_cursor_type): Partially undo 2002-03-01
Only in emacs-cvs-20030904/src: ChangeLog.~1.3360.~
diff -bur emacs-cvs-20030904.orig/src/makefile.w32-in emacs-cvs-20030904/src/makefile.w32-in
--- emacs-cvs-20030904.orig/src/makefile.w32-in	2003-09-03 10:15:39.000000000 +0200
+++ emacs-cvs-20030904/src/makefile.w32-in	2003-09-06 01:50:36.000000000 +0200
@@ -141,6 +141,7 @@
 	$(USER32)	\
 	$(MPR)		\
 	$(SHELL32)	\
+	$(WINSPOOL)	\
 	$(libc)
 
 #
diff -bur emacs-cvs-20030904.orig/src/w32fns.c emacs-cvs-20030904/src/w32fns.c
--- emacs-cvs-20030904.orig/src/w32fns.c	2003-09-03 10:15:41.000000000 +0200
+++ emacs-cvs-20030904/src/w32fns.c	2003-09-05 23:41:01.000000000 +0200
@@ -51,6 +51,7 @@
 #include <commdlg.h>
 #include <shellapi.h>
 #include <ctype.h>
+#include <winspool.h>
 
 #include <dlgs.h>
 #define FILE_NAME_TEXT_FIELD edt1
@@ -13925,6 +13926,76 @@
   return value;
 }
 \f
+DEFUN ("default-printer-name", Fdefault_printer_name, Sdefault_printer_name,
+       0, 0, 0, doc: /* Return the name of Windows default printer device.  */)
+     ()
+{
+  static char pname_buf[256];
+  int err;
+  HANDLE hPrn;
+  PRINTER_INFO_2 *ppi2 = NULL;
+  DWORD dwNeeded = 0, dwReturned = 0;
+
+  /* Retrieve the default string from Win.ini (the registry).
+   * String will be in form "printername,drivername,portname".
+   * This is the most portable way to get the default printer. */
+  if (GetProfileString ("windows", "device", ",,", pname_buf, sizeof (pname_buf)) <= 0)
+    return Qnil;
+  /* printername precedes first "," character */
+  strtok (pname_buf, ",");
+  /* We want to know more than the printer name */
+  if (!OpenPrinter (pname_buf, &hPrn, NULL))
+    return Qnil;
+  GetPrinter (hPrn, 2, NULL, 0, &dwNeeded);
+  if (dwNeeded == 0)
+    {
+      ClosePrinter (hPrn);
+      return Qnil;
+    }
+  /* Allocate memory for the PRINTER_INFO_2 struct */
+  ppi2 = (PRINTER_INFO_2 *) xmalloc (dwNeeded);
+  if (!ppi2)
+    {
+      ClosePrinter (hPrn);
+      return Qnil;
+    }
+  /* Call GetPrinter() again with big enouth memory block */
+  err = GetPrinter (hPrn, 2, (LPBYTE)ppi2, dwNeeded, &dwReturned);
+  ClosePrinter (hPrn);
+  if (!err)
+    {
+      xfree(ppi2);
+      return Qnil;
+    }
+
+  if (ppi2)
+    {
+      if (ppi2->Attributes & PRINTER_ATTRIBUTE_SHARED && ppi2->pServerName)
+        {
+	  /* a remote printer */
+	  if (*ppi2->pServerName == '\\')
+	    _snprintf(pname_buf, sizeof (pname_buf), "%s\\%s", ppi2->pServerName,
+		      ppi2->pShareName);
+	  else
+	    _snprintf(pname_buf, sizeof (pname_buf), "\\\\%s\\%s", ppi2->pServerName,
+		      ppi2->pShareName);
+	  pname_buf[sizeof (pname_buf) - 1] = '\0';
+	}
+      else
+        {
+	  /* a local printer */
+	  strncpy(pname_buf, ppi2->pPortName, sizeof (pname_buf));
+	  pname_buf[sizeof (pname_buf) - 1] = '\0';
+	  /* `pPortName' can include several ports, delimited by ','.
+	   * we only use the first one. */
+	  strtok(pname_buf, ",");
+	}
+      xfree(ppi2);
+    }
+
+  return build_string (pname_buf);
+}
+\f
 /***********************************************************************
 			    Initialization
  ***********************************************************************/
@@ -14377,6 +14448,7 @@
   defsubr (&Sw32_find_bdf_fonts);
 
   defsubr (&Sfile_system_info);
+  defsubr (&Sdefault_printer_name);
 
   /* Setting callback functions for fontset handler.  */
   get_font_info_func = w32_get_font_info;



-- 
Peter 'Luna' Runestig (fd. Altberg), Sweden <peter@runestig.com>
PGP Key ID: 0xD07BBE13
Fingerprint: 7B5C 1F48 2997 C061 DE4B  42EA CB99 A35C D07B BE13
AOL Instant Messenger Screen name: PRunestig
Yahoo! Messenger profile name: altberg

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

* Re: Windows port: using Windows' default printer
  2003-09-12 19:34       ` Peter 'Luna' Runestig
@ 2003-09-13 10:04         ` Eli Zaretskii
  2003-09-13 10:35           ` Jason Rumney
  2003-09-15 14:52         ` Stefan Monnier
  1 sibling, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2003-09-13 10:04 UTC (permalink / raw)
  Cc: emacs-devel

> Date: 12 Sep 2003 21:34:17 +0200
> From: "Peter 'Luna' Runestig" <peter@runestig.com>
> 
> This is a reworked version of the `w32-default-printer-device' variable
> patch I posted in March 2002. After a private mail exchange with Jason
> Rumney, I followed his ideas, and instead implemented a
> `default-printer-name' function, that is to be used if `printer-name'
> is nil.

Ouch!  Yet another symbol whose name is SOMETHING-printer-name, and
yet another way of specifying the default printer?

> +DEFUN ("default-printer-name", Fdefault_printer_name, Sdefault_printer_name,
> +       0, 0, 0, doc: /* Return the name of Windows default printer device.  */)

I understand the need for this function, but why does it need to be
called each time we want to print?  Does the default printer get
changed that often?

How about if we call this function only once, at startup, and put the
result into `printer-name'?  Would that be okay?

If Windows sends some kind of message when the default printer
changes, perhaps you could arrange for NTEmacs to listen to that
message and update `printer-name' automatically when it comes.
Failing that, we could tell the user to do that manually (after all, a
change in the default printer is something the user should be aware
of, right?).

WDYT?

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

* Re: Windows port: using Windows' default printer
  2003-09-13 10:04         ` Eli Zaretskii
@ 2003-09-13 10:35           ` Jason Rumney
  2003-09-13 14:39             ` Eli Zaretskii
  0 siblings, 1 reply; 25+ messages in thread
From: Jason Rumney @ 2003-09-13 10:35 UTC (permalink / raw)
  Cc: Peter 'Luna' Runestig, emacs-devel

"Eli Zaretskii" <eliz@elta.co.il> writes:

> How about if we call this function only once, at startup, and put the
> result into `printer-name'?  Would that be okay?
> 
> If Windows sends some kind of message when the default printer
> changes, perhaps you could arrange for NTEmacs to listen to that
> message and update `printer-name' automatically when it comes.

I think that is something like the original approach Peter took, but
the problem I saw with that is that you cannot distinguish between
printer-name that has been set to the default printer at startup, and
printer-name that has been customized by the user. So changing it
automatically later would potentially be a mistake.

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

* Re: Windows port: using Windows' default printer
  2003-09-13 10:35           ` Jason Rumney
@ 2003-09-13 14:39             ` Eli Zaretskii
  2003-09-13 19:44               ` Peter 'Luna' Runestig
  0 siblings, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2003-09-13 14:39 UTC (permalink / raw)
  Cc: peter, emacs-devel

> From: Jason Rumney <jasonr@gnu.org>
> Date: 13 Sep 2003 11:35:19 +0100
> > 
> > If Windows sends some kind of message when the default printer
> > changes, perhaps you could arrange for NTEmacs to listen to that
> > message and update `printer-name' automatically when it comes.
> 
> I think that is something like the original approach Peter took, but
> the problem I saw with that is that you cannot distinguish between
> printer-name that has been set to the default printer at startup, and
> printer-name that has been customized by the user. So changing it
> automatically later would potentially be a mistake.

You are probably right, although I think there's some way to make this
distinction (I vaguely recall that some code pulls such a trick).

But in case there's no way, how about calling the function to update
`printer-name' only on startup--would that be good enough?

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

* Re: Windows port: using Windows' default printer
  2003-09-13 14:39             ` Eli Zaretskii
@ 2003-09-13 19:44               ` Peter 'Luna' Runestig
  2003-09-13 20:32                 ` Kai Grossjohann
  2003-09-13 23:44                 ` Eli Zaretskii
  0 siblings, 2 replies; 25+ messages in thread
From: Peter 'Luna' Runestig @ 2003-09-13 19:44 UTC (permalink / raw)
  Cc: emacs-devel, Jason Rumney

On 2003-09-13 16:39, Eli Zaretskii wrote:
[...]
> But in case there's no way, how about calling the function to update
> `printer-name' only on startup--would that be good enough?

I think it's vital to follow any change to the Windows default printer
during the emacs session, it would be quite annoying otherwise. If you
think fetching the default printer device name all the way, at every use
of the printer, gets you too much overhead (I don't think that's a
problem at all, but...), one could cache the value, and only refresh it
when you actually change the default printer, by catching the
WM_SETTINGCHANGE window message, like it's done in my original draft patch.

-- 
Peter 'Luna' Runestig (fd. Altberg), Sweden <peter@runestig.com>
PGP Key ID: 0xD07BBE13
Fingerprint: 7B5C 1F48 2997 C061 DE4B  42EA CB99 A35C D07B BE13
AOL Instant Messenger Screen name: PRunestig
Yahoo! Messenger profile name: altberg

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

* Re: Windows port: using Windows' default printer
  2003-09-13 19:44               ` Peter 'Luna' Runestig
@ 2003-09-13 20:32                 ` Kai Grossjohann
  2003-09-13 22:13                   ` Jason Rumney
  2003-09-13 23:44                 ` Eli Zaretskii
  1 sibling, 1 reply; 25+ messages in thread
From: Kai Grossjohann @ 2003-09-13 20:32 UTC (permalink / raw)


"Peter 'Luna' Runestig" <peter@runestig.com> writes:

> I think it's vital to follow any change to the Windows default printer
> during the emacs session, it would be quite annoying otherwise. If you
> think fetching the default printer device name all the way, at every use
> of the printer, gets you too much overhead (I don't think that's a
> problem at all, but...), one could cache the value, and only refresh it
> when you actually change the default printer, by catching the
> WM_SETTINGCHANGE window message, like it's done in my original draft patch.

But if printer-name changes behind the user's back, how could the user
choose another printer?

How about making a special value for printer-name that means to use
the default Windows printer?
-- 
Two cafe au lait please, but without milk.

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

* Re: Windows port: using Windows' default printer
  2003-09-13 20:32                 ` Kai Grossjohann
@ 2003-09-13 22:13                   ` Jason Rumney
  0 siblings, 0 replies; 25+ messages in thread
From: Jason Rumney @ 2003-09-13 22:13 UTC (permalink / raw)
  Cc: emacs-devel

Kai Grossjohann <kai.grossjohann@gmx.net> writes:

> But if printer-name changes behind the user's back, how could the user
> choose another printer?
> 
> How about making a special value for printer-name that means to use
> the default Windows printer?

And we're back where we started. That "special value" was nil, which
is consistant with when lpr is used to print.

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

* Re: Windows port: using Windows' default printer
  2003-09-13 19:44               ` Peter 'Luna' Runestig
  2003-09-13 20:32                 ` Kai Grossjohann
@ 2003-09-13 23:44                 ` Eli Zaretskii
  2003-09-14  9:40                   ` Peter 'Luna' Runestig
  1 sibling, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2003-09-13 23:44 UTC (permalink / raw)
  Cc: emacs-devel

> Date: Sat, 13 Sep 2003 21:44:30 +0200
> From: "Peter 'Luna' Runestig" <peter@runestig.com>
> 
> On 2003-09-13 16:39, Eli Zaretskii wrote:
> [...]
> > But in case there's no way, how about calling the function to update
> > `printer-name' only on startup--would that be good enough?
> 
> I think it's vital to follow any change to the Windows default printer
> during the emacs session, it would be quite annoying otherwise.

If it's quite annoying, we would be hearing from Windows users by now.

I still think we could simply tell the user change the value whenever
she changes the default printer.  But that's me.

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

* Re: Windows port: using Windows' default printer
  2003-09-13 23:44                 ` Eli Zaretskii
@ 2003-09-14  9:40                   ` Peter 'Luna' Runestig
  0 siblings, 0 replies; 25+ messages in thread
From: Peter 'Luna' Runestig @ 2003-09-14  9:40 UTC (permalink / raw)
  Cc: emacs-devel

On 2003-09-14 01:44, Eli Zaretskii wrote:
>> Date: Sat, 13 Sep 2003 21:44:30 +0200
>> From: "Peter 'Luna' Runestig" <peter@runestig.com>
>> 
>> On 2003-09-13 16:39, Eli Zaretskii wrote:
>> [...]
>> > But in case there's no way, how about calling the function to update
>> > `printer-name' only on startup--would that be good enough?
>> 
>> I think it's vital to follow any change to the Windows default printer
>> during the emacs session, it would be quite annoying otherwise.
> 
> If it's quite annoying, we would be hearing from Windows users by now.
> 
> I still think we could simply tell the user change the value whenever
> she changes the default printer.  But that's me.

Since printing from Emacs currently is very different from printing from
any other Windows application, maybe they don't complain about the
details. I for one never printed anything from Emacs before implementing
this, since I move between offices (and home) with my laptop, thus
having to keep track of different printers' device names, and it was too
much work for lazy me. But if we implement a way to use the Windows
default printer (i.e. the "normal" Windows way), but then only implement
it half-way (by not following any change to the default printer), then
maybe more people than me would find it annoying.

-- 
Peter 'Luna' Runestig (fd. Altberg), Sweden <peter@runestig.com>
PGP Key ID: 0xD07BBE13
Fingerprint: 7B5C 1F48 2997 C061 DE4B  42EA CB99 A35C D07B BE13
AOL Instant Messenger Screen name: PRunestig
Yahoo! Messenger profile name: altberg

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

* Re: Windows port: using Windows' default printer
  2003-09-12 19:34       ` Peter 'Luna' Runestig
  2003-09-13 10:04         ` Eli Zaretskii
@ 2003-09-15 14:52         ` Stefan Monnier
  2003-09-21 13:19           ` Eli Zaretskii
  1 sibling, 1 reply; 25+ messages in thread
From: Stefan Monnier @ 2003-09-15 14:52 UTC (permalink / raw)
  Cc: emacs-devel

> This is a reworked version of the `w32-default-printer-device' variable
> patch I posted in March 2002. After a private mail exchange with Jason
> Rumney, I followed his ideas, and instead implemented a
> `default-printer-name' function, that is to be used if `printer-name'
> is nil. I quote Jason's description of the idea:

I think the C part of the code is fine and the use of `printer-name'
is fine as well, but I wish that the use of default-printer-name could be
confined to a single spot (in Unix, it's in `lpr' so Emacs doesn't know
about it).  We probably need to create a function that either calls `lpr'
or calls windows' printing code (using default-printer-name if necessary)
and then have both lpr.el and ps-print.el use this function.

In the mean time, your patch looks like a step in the right direction.


        Stefan


>>>>>>> 
> [...] Rather, you should expose a function to lisp (using the DEFUN C
> macro) which returns the default printer name, then modify the code that
> uses printer-name (and ps-printer-name) to call this function if
> printer-name is nil and the function is available.

> If possible, avoid w32- specific variables, function names and tests,
> then if MacOS or other systems need to do a similar thing, they just
> need to implement a function of the same name. This is much cleaner than
> having branches all over the place to handle specific platforms.

> An example of the Lisp required to do what I'm thinking of would be:

>     (let ((printer-name (or printer-name 
>                             (and (fboundp 'default-printer-name)
>                                  (default-printer-name)))))
>        ;; Code that uses printer-name here
>       )
> <<<<<<


> diff -bur emacs-cvs-20030904.orig/lisp/ChangeLog emacs-cvs-20030904/lisp/ChangeLog
> --- emacs-cvs-20030904.orig/lisp/ChangeLog	2003-09-03 10:14:52.000000000 +0200
> +++ emacs-cvs-20030904/lisp/ChangeLog	2003-09-08 09:01:53.000000000 +0200
> @@ -1,3 +1,8 @@
> +2003-09-05  Peter Runestig <peter@runestig.com>
> +
> +	* dos-w32.el, lpr.el, ps-print.el, play/handwrite.el: Added support for
> +	the `default-printer-name' function.
> +
>  2003-09-02  Jason Rumney  <jasonr@gnu.org>
 
>  	* international/titdic-cnv.el (tsang-quick-converter): Fix broken
> diff -bur emacs-cvs-20030904.orig/lisp/dos-w32.el emacs-cvs-20030904/lisp/dos-w32.el
> --- emacs-cvs-20030904.orig/lisp/dos-w32.el	2003-09-03 10:14:55.000000000 +0200
> +++ emacs-cvs-20030904/lisp/dos-w32.el	2003-09-05 22:50:41.000000000 +0200
> @@ -378,7 +378,9 @@
>  	 (printer (or (and (boundp 'dos-printer)
>  			   (stringp (symbol-value 'dos-printer))
>  			   (symbol-value 'dos-printer))
> -		      printer-name)))
> +		      printer-name
> +		      (and (fboundp 'default-printer-name)
> +			   (default-printer-name)))))
>      (or (eq coding-system-for-write 'no-conversion)
>  	(setq coding-system-for-write
>  	      (aref eol-type 1)))	; force conversion to DOS EOLs
> @@ -411,7 +413,9 @@
>    (let ((printer (or (and (boundp 'dos-ps-printer)
>  			  (stringp (symbol-value 'dos-ps-printer))
>  			  (symbol-value 'dos-ps-printer))
> -		     ps-printer-name)))
> +		     ps-printer-name
> +		     (and (fboundp 'default-printer-name)
> +			  (default-printer-name)))))
>      (direct-print-region-helper printer start end lpr-prog
>  				delete-text buf display rest)))
 
> diff -bur emacs-cvs-20030904.orig/lisp/lpr.el emacs-cvs-20030904/lisp/lpr.el
> --- emacs-cvs-20030904.orig/lisp/lpr.el	2003-09-03 10:14:58.000000000 +0200
> +++ emacs-cvs-20030904/lisp/lpr.el	2003-09-05 22:50:41.000000000 +0200
> @@ -255,9 +255,12 @@
>  		    ;; These belong in pr if we are using that.
>  		    (and lpr-add-switches lpr-headers-switches
>  			 (list "-T" title))
> -		    (and (stringp printer-name)
> +		    (or (and (stringp printer-name)
>  			 (list (concat lpr-printer-switch
>  				       printer-name)))
> +			(and (fboundp 'default-printer-name)
> +			     (list (concat lpr-printer-switch
> +					   (default-printer-name)))))
>  		    nswitches))
>        (if (markerp end)
>  	  (set-marker end nil))
> diff -bur emacs-cvs-20030904.orig/lisp/play/handwrite.el emacs-cvs-20030904/lisp/play/handwrite.el
> --- emacs-cvs-20030904.orig/lisp/play/handwrite.el	2003-09-03 10:15:15.000000000 +0200
> +++ emacs-cvs-20030904/lisp/play/handwrite.el	2003-09-05 22:50:41.000000000 +0200
> @@ -335,7 +335,9 @@
>  	  (let* ((coding-system-for-write 'raw-text-unix)
>  		 (ps-printer-name (or ps-printer-name
>  				      (and (boundp 'printer-name)
> -					   printer-name)))
> +					   printer-name)
> +				      (and (fboundp 'default-printer-name)
> +					   (default-printer-name))))
>  		 (ps-lpr-switches
>  		  (if (stringp ps-printer-name)
>  		      (list (concat "-P" ps-printer-name)))))
> diff -bur emacs-cvs-20030904.orig/lisp/ps-print.el emacs-cvs-20030904/lisp/ps-print.el
> --- emacs-cvs-20030904.orig/lisp/ps-print.el	2003-09-03 10:15:00.000000000 +0200
> +++ emacs-cvs-20030904/lisp/ps-print.el	2003-09-05 22:50:41.000000000 +0200
> @@ -6563,7 +6563,9 @@
>  	(let* ((coding-system-for-write 'raw-text-unix)
>  	       (ps-printer-name (or ps-printer-name
>  				    (and (boundp 'printer-name)
> -					 (symbol-value 'printer-name))))
> +					 (symbol-value 'printer-name))
> +				    (and (fboundp 'default-printer-name)
> +					 (default-printer-name))))
>  	       (ps-lpr-switches
>  		(append ps-lpr-switches
>  			(and (stringp ps-printer-name)
> diff -bur emacs-cvs-20030904.orig/nt/ChangeLog emacs-cvs-20030904/nt/ChangeLog
> --- emacs-cvs-20030904.orig/nt/ChangeLog	2003-09-04 09:19:35.000000000 +0200
> +++ emacs-cvs-20030904/nt/ChangeLog	2003-09-08 09:04:42.000000000 +0200
> @@ -1,3 +1,7 @@
> +2003-09-05  Peter Runestig <peter@runestig.com>
> +
> +	* gmake.defs, nmake.defs: Add linking to ``winspool.lib''.
> +
>  2003-09-03  Peter Runestig <peter@runestig.com>
 
>  	* configure.bat: Create ``makefile'' in directories man, lispref
> diff -bur emacs-cvs-20030904.orig/nt/gmake.defs emacs-cvs-20030904/nt/gmake.defs
> --- emacs-cvs-20030904.orig/nt/gmake.defs	2003-09-03 10:15:31.000000000 +0200
> +++ emacs-cvs-20030904/nt/gmake.defs	2003-09-05 22:50:41.000000000 +0200
> @@ -177,6 +177,7 @@
>  USER32		= -luser32
>  WSOCK32		= -lwsock32
>  WINMM     = -lwinmm
> +WINSPOOL	= -lwinspool
 
>  ifdef NOOPT
>  DEBUG_CFLAGS	= -DEMACSDEBUG
> diff -bur emacs-cvs-20030904.orig/nt/nmake.defs emacs-cvs-20030904/nt/nmake.defs
> --- emacs-cvs-20030904.orig/nt/nmake.defs	2003-09-03 10:15:31.000000000 +0200
> +++ emacs-cvs-20030904/nt/nmake.defs	2003-09-05 22:50:41.000000000 +0200
> @@ -124,6 +124,7 @@
>  USER32		= user32.lib
>  WSOCK32		= wsock32.lib
>  WINMM     = winmm.lib
> +WINSPOOL	= winspool.lib
 
>  !ifdef NOOPT
>  DEBUG_CFLAGS	= -DEMACSDEBUG
> diff -bur emacs-cvs-20030904.orig/src/ChangeLog emacs-cvs-20030904/src/ChangeLog
> --- emacs-cvs-20030904.orig/src/ChangeLog	2003-09-03 10:15:33.000000000 +0200
> +++ emacs-cvs-20030904/src/ChangeLog	2003-09-08 09:06:20.000000000 +0200
> @@ -1,3 +1,7 @@
> +2003-09-05  Peter Runestig <peter@runestig.com>
> +
> +	* makefile.w32-in, w32fns.c: Add `default-printer-name' function.
> +
>  2003-09-03  Kim F. Storm  <storm@cua.dk>
 
>  	* xdisp.c (get_window_cursor_type): Partially undo 2002-03-01
> Only in emacs-cvs-20030904/src: ChangeLog.~1.3360.~
> diff -bur emacs-cvs-20030904.orig/src/makefile.w32-in emacs-cvs-20030904/src/makefile.w32-in
> --- emacs-cvs-20030904.orig/src/makefile.w32-in	2003-09-03 10:15:39.000000000 +0200
> +++ emacs-cvs-20030904/src/makefile.w32-in	2003-09-06 01:50:36.000000000 +0200
> @@ -141,6 +141,7 @@
>  	$(USER32)	\
>  	$(MPR)		\
>  	$(SHELL32)	\
> +	$(WINSPOOL)	\
>  	$(libc)
 
>  #
> diff -bur emacs-cvs-20030904.orig/src/w32fns.c emacs-cvs-20030904/src/w32fns.c
> --- emacs-cvs-20030904.orig/src/w32fns.c	2003-09-03 10:15:41.000000000 +0200
> +++ emacs-cvs-20030904/src/w32fns.c	2003-09-05 23:41:01.000000000 +0200
> @@ -51,6 +51,7 @@
>  #include <commdlg.h>
>  #include <shellapi.h>
>  #include <ctype.h>
> +#include <winspool.h>
 
>  #include <dlgs.h>
>  #define FILE_NAME_TEXT_FIELD edt1
> @@ -13925,6 +13926,76 @@
>    return value;
>  }
>  \f
> +DEFUN ("default-printer-name", Fdefault_printer_name, Sdefault_printer_name,
> +       0, 0, 0, doc: /* Return the name of Windows default printer device.  */)
> +     ()
> +{
> +  static char pname_buf[256];
> +  int err;
> +  HANDLE hPrn;
> +  PRINTER_INFO_2 *ppi2 = NULL;
> +  DWORD dwNeeded = 0, dwReturned = 0;
> +
> +  /* Retrieve the default string from Win.ini (the registry).
> +   * String will be in form "printername,drivername,portname".
> +   * This is the most portable way to get the default printer. */
> +  if (GetProfileString ("windows", "device", ",,", pname_buf, sizeof (pname_buf)) <= 0)
> +    return Qnil;
> +  /* printername precedes first "," character */
> +  strtok (pname_buf, ",");
> +  /* We want to know more than the printer name */
> +  if (!OpenPrinter (pname_buf, &hPrn, NULL))
> +    return Qnil;
> +  GetPrinter (hPrn, 2, NULL, 0, &dwNeeded);
> +  if (dwNeeded == 0)
> +    {
> +      ClosePrinter (hPrn);
> +      return Qnil;
> +    }
> +  /* Allocate memory for the PRINTER_INFO_2 struct */
> +  ppi2 = (PRINTER_INFO_2 *) xmalloc (dwNeeded);
> +  if (!ppi2)
> +    {
> +      ClosePrinter (hPrn);
> +      return Qnil;
> +    }
> +  /* Call GetPrinter() again with big enouth memory block */
> +  err = GetPrinter (hPrn, 2, (LPBYTE)ppi2, dwNeeded, &dwReturned);
> +  ClosePrinter (hPrn);
> +  if (!err)
> +    {
> +      xfree(ppi2);
> +      return Qnil;
> +    }
> +
> +  if (ppi2)
> +    {
> +      if (ppi2->Attributes & PRINTER_ATTRIBUTE_SHARED && ppi2->pServerName)
> +        {
> +	  /* a remote printer */
> +	  if (*ppi2->pServerName == '\\')
> +	    _snprintf(pname_buf, sizeof (pname_buf), "%s\\%s", ppi2->pServerName,
> +		      ppi2->pShareName);
> +	  else
> +	    _snprintf(pname_buf, sizeof (pname_buf), "\\\\%s\\%s", ppi2->pServerName,
> +		      ppi2->pShareName);
> +	  pname_buf[sizeof (pname_buf) - 1] = '\0';
> +	}
> +      else
> +        {
> +	  /* a local printer */
> +	  strncpy(pname_buf, ppi2->pPortName, sizeof (pname_buf));
> +	  pname_buf[sizeof (pname_buf) - 1] = '\0';
> +	  /* `pPortName' can include several ports, delimited by ','.
> +	   * we only use the first one. */
> +	  strtok(pname_buf, ",");
> +	}
> +      xfree(ppi2);
> +    }
> +
> +  return build_string (pname_buf);
> +}
> +\f
>  /***********************************************************************
>  			    Initialization
>   ***********************************************************************/
> @@ -14377,6 +14448,7 @@
>    defsubr (&Sw32_find_bdf_fonts);
 
>    defsubr (&Sfile_system_info);
> +  defsubr (&Sdefault_printer_name);
 
>    /* Setting callback functions for fontset handler.  */
>    get_font_info_func = w32_get_font_info;



> -- 
> Peter 'Luna' Runestig (fd. Altberg), Sweden <peter@runestig.com>
> PGP Key ID: 0xD07BBE13
> Fingerprint: 7B5C 1F48 2997 C061 DE4B  42EA CB99 A35C D07B BE13
> AOL Instant Messenger Screen name: PRunestig
> Yahoo! Messenger profile name: altberg



> _______________________________________________
> Emacs-devel mailing list
> Emacs-devel@gnu.org
> http://mail.gnu.org/mailman/listinfo/emacs-devel

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

* Re: Windows port: using Windows' default printer
  2003-09-15 14:52         ` Stefan Monnier
@ 2003-09-21 13:19           ` Eli Zaretskii
  2003-09-21 19:51             ` Stefan Monnier
  0 siblings, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2003-09-21 13:19 UTC (permalink / raw)
  Cc: peter, emacs-devel

> From: "Stefan Monnier" <monnier@IRO.UMontreal.CA>
> Date: 15 Sep 2003 10:52:23 -0400
> 
> I think the C part of the code is fine and the use of `printer-name'
> is fine as well, but I wish that the use of default-printer-name could be
> confined to a single spot (in Unix, it's in `lpr' so Emacs doesn't know
> about it).  We probably need to create a function that either calls `lpr'
> or calls windows' printing code (using default-printer-name if necessary)
> and then have both lpr.el and ps-print.el use this function.

If I understand you correctly, we already have such a function in
lpr.el: it's `print-region-function'.  dos-w32.el defines it for the
Windows and the DOS ports.

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

* Re: Windows port: using Windows' default printer
  2003-09-21 13:19           ` Eli Zaretskii
@ 2003-09-21 19:51             ` Stefan Monnier
  2003-09-22  6:07               ` Eli Zaretskii
  2003-09-23 16:28               ` Peter 'Luna' Runestig
  0 siblings, 2 replies; 25+ messages in thread
From: Stefan Monnier @ 2003-09-21 19:51 UTC (permalink / raw)
  Cc: peter, emacs-devel

>> is fine as well, but I wish that the use of default-printer-name could be
>> confined to a single spot (in Unix, it's in `lpr' so Emacs doesn't know
>> about it).  We probably need to create a function that either calls `lpr'
>> or calls windows' printing code (using default-printer-name if necessary)
>> and then have both lpr.el and ps-print.el use this function.

> If I understand you correctly, we already have such a function in
> lpr.el: it's `print-region-function'.  dos-w32.el defines it for the
> Windows and the DOS ports.

Does ps-print.el use it ?
If so, great, we just need to add the `default-printer-name' stuff
to it and be done with Itô,


        Stefan

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

* Re: Windows port: using Windows' default printer
  2003-09-21 19:51             ` Stefan Monnier
@ 2003-09-22  6:07               ` Eli Zaretskii
  2003-09-23 16:28               ` Peter 'Luna' Runestig
  1 sibling, 0 replies; 25+ messages in thread
From: Eli Zaretskii @ 2003-09-22  6:07 UTC (permalink / raw)
  Cc: peter, emacs-devel

> From: "Stefan Monnier" <monnier@IRO.UMontreal.CA>
> Date: 21 Sep 2003 15:51:01 -0400
> 
> > If I understand you correctly, we already have such a function in
> > lpr.el: it's `print-region-function'.  dos-w32.el defines it for the
> > Windows and the DOS ports.
> 
> Does ps-print.el use it ?

No, but it has a similar function `ps-print-region-function', which
is also appropriately defined by dos-w32.el.

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

* Re: Windows port: using Windows' default printer
  2003-09-21 19:51             ` Stefan Monnier
  2003-09-22  6:07               ` Eli Zaretskii
@ 2003-09-23 16:28               ` Peter 'Luna' Runestig
  2003-09-24 18:25                 ` Eli Zaretskii
  1 sibling, 1 reply; 25+ messages in thread
From: Peter 'Luna' Runestig @ 2003-09-23 16:28 UTC (permalink / raw)
  Cc: Eli Zaretskii, emacs-devel

On 2003-09-21 21:51, Stefan Monnier wrote:
>>> is fine as well, but I wish that the use of default-printer-name could be
>>> confined to a single spot (in Unix, it's in `lpr' so Emacs doesn't know
>>> about it).  We probably need to create a function that either calls `lpr'
>>> or calls windows' printing code (using default-printer-name if necessary)
>>> and then have both lpr.el and ps-print.el use this function.
> 
>> If I understand you correctly, we already have such a function in
>> lpr.el: it's `print-region-function'.  dos-w32.el defines it for the
>> Windows and the DOS ports.
> 
> Does ps-print.el use it ?
> If so, great, we just need to add the `default-printer-name' stuff
> to it and be done with Itô,

Isn't this what my patch does?

dos-w32.el: Add `default-printer-name' stuff to
`direct-print-region-function' and `direct-ps-print-region-function'.

I also tampered with the following files, but maybe that isn't necessary:

lpr.el: Add `default-printer-name' stuff to `print-region-1'.
ps-print.el: Add `default-printer-name' stuff to `ps-do-despool'.
play/handwrite.el: Add `default-printer-name' stuff to `handwrite'.


-- 
Peter 'Luna' Runestig (fd. Altberg), Sweden <peter@runestig.com>
PGP Key ID: 0xD07BBE13
Fingerprint: 7B5C 1F48 2997 C061 DE4B  42EA CB99 A35C D07B BE13
AOL Instant Messenger Screen name: PRunestig
Yahoo! Messenger profile name: altberg

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

* Re: Windows port: using Windows' default printer
  2003-09-23 16:28               ` Peter 'Luna' Runestig
@ 2003-09-24 18:25                 ` Eli Zaretskii
  2003-09-24 19:22                   ` Luc Teirlinck
  2003-09-25 13:26                   ` Peter 'Luna' Runestig
  0 siblings, 2 replies; 25+ messages in thread
From: Eli Zaretskii @ 2003-09-24 18:25 UTC (permalink / raw)
  Cc: emacs-devel

> Date: Tue, 23 Sep 2003 18:28:56 +0200
> From: "Peter 'Luna' Runestig" <peter@runestig.com>
> > 
> >> If I understand you correctly, we already have such a function in
> >> lpr.el: it's `print-region-function'.  dos-w32.el defines it for the
> >> Windows and the DOS ports.
> > 
> > Does ps-print.el use it ?
> > If so, great, we just need to add the `default-printer-name' stuff
> > to it and be done with It\x7f,
> 
> Isn't this what my patch does?

Yes, but why did you need to test for default-printer-name to be
fboundp?  It should simply be called unconditionally, and we should
have some provision for the user to override that with printer-name.

> I also tampered with the following files, but maybe that isn't necessary:
> 
> lpr.el: Add `default-printer-name' stuff to `print-region-1'.
> ps-print.el: Add `default-printer-name' stuff to `ps-do-despool'.
> play/handwrite.el: Add `default-printer-name' stuff to `handwrite'.

This shouldn't be necessary.

I still think that, even for Windows, it's overhead to call
default-printer-name each time we print something.  But that's me.

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

* Re: Windows port: using Windows' default printer
  2003-09-24 18:25                 ` Eli Zaretskii
@ 2003-09-24 19:22                   ` Luc Teirlinck
  2003-09-25 13:26                   ` Peter 'Luna' Runestig
  1 sibling, 0 replies; 25+ messages in thread
From: Luc Teirlinck @ 2003-09-24 19:22 UTC (permalink / raw)
  Cc: peter, emacs-devel

Eli Zaretskii wrote:

   I still think that, even for Windows, it's overhead to call
   default-printer-name each time we print something.  But that's me.

If the objection is aesthetic, then it is indeed a matter of personal
taste.  Otherwise, would it not be possible for somebody to measure
how much time this call takes on a reasonably slow machine?  I do not
use MS Windows, so I can not do it.  It seems doubtful that it would
take any appreciable time just to determine the default printer.

Sincerely,

Luc.

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

* Re: Windows port: using Windows' default printer
  2003-09-24 18:25                 ` Eli Zaretskii
  2003-09-24 19:22                   ` Luc Teirlinck
@ 2003-09-25 13:26                   ` Peter 'Luna' Runestig
  2003-10-22 10:35                     ` Peter 'Luna' Runestig
  1 sibling, 1 reply; 25+ messages in thread
From: Peter 'Luna' Runestig @ 2003-09-25 13:26 UTC (permalink / raw)
  Cc: emacs-devel

"Eli Zaretskii" <eliz@elta.co.il> writes:
> > Isn't this what my patch does?
> 
> Yes, but why did you need to test for default-printer-name to be
> fboundp?  It should simply be called unconditionally, and we should
> have some provision for the user to override that with printer-name.

Yes, you're right of course, no need for fboundp in dos-w32.el. The
original idea was that you could have defined a `default-printer-name'
function for any given platform, thus the general idea of the fboundp
test. But since dos-w32.el belongs to the same platform as the rest of
my code, that test is silly. And `default-printer-name' is only called
if printer-name/ps-printer-name is nil.

> > I also tampered with the following files, but maybe that isn't necessary:
> > 
> > lpr.el: Add `default-printer-name' stuff to `print-region-1'.
> > ps-print.el: Add `default-printer-name' stuff to `ps-do-despool'.
> > play/handwrite.el: Add `default-printer-name' stuff to `handwrite'.
> 
> This shouldn't be necessary.

The reason for me messing with those files, was the line of thinking
from the original idea, described above.

> I still think that, even for Windows, it's overhead to call
> default-printer-name each time we print something.  But that's me.

I did a profiling test on my 750 MHz PentiumIII, it takes about 5
ms. Anyway, here is a stripped down, "w32-only" version:

diff -bur emacs-cvs-20030904.orig/lisp/ChangeLog emacs-cvs-20030904/lisp/ChangeLog
--- emacs-cvs-20030904.orig/lisp/ChangeLog	2003-09-03 10:14:52.000000000 +0200
+++ emacs-cvs-20030904/lisp/ChangeLog	2003-09-08 09:01:53.000000000 +0200
@@ -1,3 +1,7 @@
+2003-09-05  Peter Runestig <peter@runestig.com>
+
+	* dos-w32.el: Added support for	the `default-printer-name' function.
+
 2003-09-02  Jason Rumney  <jasonr@gnu.org>
 
 	* international/titdic-cnv.el (tsang-quick-converter): Fix broken
diff -bur emacs-cvs-20030904.orig/lisp/dos-w32.el emacs-cvs-20030904/lisp/dos-w32.el
--- emacs-cvs-20030904.orig/lisp/dos-w32.el	2003-09-03 10:14:55.000000000 +0200
+++ emacs-cvs-20030904/lisp/dos-w32.el	2003-09-05 22:50:41.000000000 +0200
@@ -378,7 +378,8 @@
 	 (printer (or (and (boundp 'dos-printer)
 			   (stringp (symbol-value 'dos-printer))
 			   (symbol-value 'dos-printer))
-		      printer-name)))
+		      printer-name
+		      (default-printer-name))))
     (or (eq coding-system-for-write 'no-conversion)
 	(setq coding-system-for-write
 	      (aref eol-type 1)))	; force conversion to DOS EOLs
@@ -411,7 +413,8 @@
   (let ((printer (or (and (boundp 'dos-ps-printer)
 			  (stringp (symbol-value 'dos-ps-printer))
 			  (symbol-value 'dos-ps-printer))
-		     ps-printer-name)))
+		     ps-printer-name
+		     (default-printer-name))))
     (direct-print-region-helper printer start end lpr-prog
 				delete-text buf display rest)))
 
diff -bur emacs-cvs-20030904.orig/nt/ChangeLog emacs-cvs-20030904/nt/ChangeLog
--- emacs-cvs-20030904.orig/nt/ChangeLog	2003-09-04 09:19:35.000000000 +0200
+++ emacs-cvs-20030904/nt/ChangeLog	2003-09-08 09:04:42.000000000 +0200
@@ -1,3 +1,7 @@
+2003-09-05  Peter Runestig <peter@runestig.com>
+
+	* gmake.defs, nmake.defs: Add linking to ``winspool.lib''.
+
 2003-09-03  Peter Runestig <peter@runestig.com>
 
 	* configure.bat: Create ``makefile'' in directories man, lispref
diff -bur emacs-cvs-20030904.orig/nt/gmake.defs emacs-cvs-20030904/nt/gmake.defs
--- emacs-cvs-20030904.orig/nt/gmake.defs	2003-09-03 10:15:31.000000000 +0200
+++ emacs-cvs-20030904/nt/gmake.defs	2003-09-05 22:50:41.000000000 +0200
@@ -177,6 +177,7 @@
 USER32		= -luser32
 WSOCK32		= -lwsock32
 WINMM     = -lwinmm
+WINSPOOL	= -lwinspool
 
 ifdef NOOPT
 DEBUG_CFLAGS	= -DEMACSDEBUG
diff -bur emacs-cvs-20030904.orig/nt/nmake.defs emacs-cvs-20030904/nt/nmake.defs
--- emacs-cvs-20030904.orig/nt/nmake.defs	2003-09-03 10:15:31.000000000 +0200
+++ emacs-cvs-20030904/nt/nmake.defs	2003-09-05 22:50:41.000000000 +0200
@@ -124,6 +124,7 @@
 USER32		= user32.lib
 WSOCK32		= wsock32.lib
 WINMM     = winmm.lib
+WINSPOOL	= winspool.lib
 
 !ifdef NOOPT
 DEBUG_CFLAGS	= -DEMACSDEBUG
diff -bur emacs-cvs-20030904.orig/src/ChangeLog emacs-cvs-20030904/src/ChangeLog
--- emacs-cvs-20030904.orig/src/ChangeLog	2003-09-03 10:15:33.000000000 +0200
+++ emacs-cvs-20030904/src/ChangeLog	2003-09-08 09:06:20.000000000 +0200
@@ -1,3 +1,7 @@
+2003-09-05  Peter Runestig <peter@runestig.com>
+
+	* makefile.w32-in, w32fns.c: Add `default-printer-name' function.
+
 2003-09-03  Kim F. Storm  <storm@cua.dk>
 
 	* xdisp.c (get_window_cursor_type): Partially undo 2002-03-01
diff -bur emacs-cvs-20030904.orig/src/makefile.w32-in emacs-cvs-20030904/src/makefile.w32-in
--- emacs-cvs-20030904.orig/src/makefile.w32-in	2003-09-03 10:15:39.000000000 +0200
+++ emacs-cvs-20030904/src/makefile.w32-in	2003-09-06 01:50:36.000000000 +0200
@@ -141,6 +141,7 @@
 	$(USER32)	\
 	$(MPR)		\
 	$(SHELL32)	\
+	$(WINSPOOL)	\
 	$(libc)
 
 #
diff -bur emacs-cvs-20030904.orig/src/w32fns.c emacs-cvs-20030904/src/w32fns.c
--- emacs-cvs-20030904.orig/src/w32fns.c	2003-09-03 10:15:41.000000000 +0200
+++ emacs-cvs-20030904/src/w32fns.c	2003-09-05 23:41:01.000000000 +0200
@@ -51,6 +51,7 @@
 #include <commdlg.h>
 #include <shellapi.h>
 #include <ctype.h>
+#include <winspool.h>
 
 #include <dlgs.h>
 #define FILE_NAME_TEXT_FIELD edt1
@@ -13925,6 +13926,76 @@
   return value;
 }
 \f
+DEFUN ("default-printer-name", Fdefault_printer_name, Sdefault_printer_name,
+       0, 0, 0, doc: /* Return the name of Windows default printer device.  */)
+     ()
+{
+  static char pname_buf[256];
+  int err;
+  HANDLE hPrn;
+  PRINTER_INFO_2 *ppi2 = NULL;
+  DWORD dwNeeded = 0, dwReturned = 0;
+
+  /* Retrieve the default string from Win.ini (the registry).
+   * String will be in form "printername,drivername,portname".
+   * This is the most portable way to get the default printer. */
+  if (GetProfileString ("windows", "device", ",,", pname_buf, sizeof (pname_buf)) <= 0)
+    return Qnil;
+  /* printername precedes first "," character */
+  strtok (pname_buf, ",");
+  /* We want to know more than the printer name */
+  if (!OpenPrinter (pname_buf, &hPrn, NULL))
+    return Qnil;
+  GetPrinter (hPrn, 2, NULL, 0, &dwNeeded);
+  if (dwNeeded == 0)
+    {
+      ClosePrinter (hPrn);
+      return Qnil;
+    }
+  /* Allocate memory for the PRINTER_INFO_2 struct */
+  ppi2 = (PRINTER_INFO_2 *) xmalloc (dwNeeded);
+  if (!ppi2)
+    {
+      ClosePrinter (hPrn);
+      return Qnil;
+    }
+  /* Call GetPrinter() again with big enouth memory block */
+  err = GetPrinter (hPrn, 2, (LPBYTE)ppi2, dwNeeded, &dwReturned);
+  ClosePrinter (hPrn);
+  if (!err)
+    {
+      xfree(ppi2);
+      return Qnil;
+    }
+
+  if (ppi2)
+    {
+      if (ppi2->Attributes & PRINTER_ATTRIBUTE_SHARED && ppi2->pServerName)
+        {
+	  /* a remote printer */
+	  if (*ppi2->pServerName == '\\')
+	    _snprintf(pname_buf, sizeof (pname_buf), "%s\\%s", ppi2->pServerName,
+		      ppi2->pShareName);
+	  else
+	    _snprintf(pname_buf, sizeof (pname_buf), "\\\\%s\\%s", ppi2->pServerName,
+		      ppi2->pShareName);
+	  pname_buf[sizeof (pname_buf) - 1] = '\0';
+	}
+      else
+        {
+	  /* a local printer */
+	  strncpy(pname_buf, ppi2->pPortName, sizeof (pname_buf));
+	  pname_buf[sizeof (pname_buf) - 1] = '\0';
+	  /* `pPortName' can include several ports, delimited by ','.
+	   * we only use the first one. */
+	  strtok(pname_buf, ",");
+	}
+      xfree(ppi2);
+    }
+
+  return build_string (pname_buf);
+}
+\f
 /***********************************************************************
 			    Initialization
  ***********************************************************************/
@@ -14377,6 +14448,7 @@
   defsubr (&Sw32_find_bdf_fonts);
 
   defsubr (&Sfile_system_info);
+  defsubr (&Sdefault_printer_name);
 
   /* Setting callback functions for fontset handler.  */
   get_font_info_func = w32_get_font_info;


-- 
Peter 'Luna' Runestig (fd. Altberg), Sweden <peter@runestig.com>
PGP Key ID: 0xD07BBE13
Fingerprint: 7B5C 1F48 2997 C061 DE4B  42EA CB99 A35C D07B BE13
AOL Instant Messenger Screen name: PRunestig
Yahoo! Messenger profile name: altberg

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

* Re: Windows port: using Windows' default printer
  2003-09-25 13:26                   ` Peter 'Luna' Runestig
@ 2003-10-22 10:35                     ` Peter 'Luna' Runestig
  2003-10-22 11:15                       ` Jason Rumney
  2003-10-22 15:58                       ` Eli Zaretskii
  0 siblings, 2 replies; 25+ messages in thread
From: Peter 'Luna' Runestig @ 2003-10-22 10:35 UTC (permalink / raw)


Hi all! Is there anything more I should do to get this patch accepted?
When it comes to the issue about calling default-printer-name each time
we print something, I can see several options:

o Leave as is (my favorite).
o Only call default-printer-name on start-up.
o Make the use of the above two ways run-time configurable.
o Add some caching functionality to default-printer-name, and trigger
  the "cache update" on WM_SETTINGCHANGE.

Cheers,
- Peter
-- 
Peter 'Luna' Runestig (fd. Altberg), Sweden <peter@runestig.com>
PGP Key ID: 0xD07BBE13
Fingerprint: 7B5C 1F48 2997 C061 DE4B  42EA CB99 A35C D07B BE13
AOL Instant Messenger Screen name: PRunestig
Yahoo! Messenger profile name: altberg

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

* Re: Windows port: using Windows' default printer
  2003-10-22 10:35                     ` Peter 'Luna' Runestig
@ 2003-10-22 11:15                       ` Jason Rumney
  2003-10-22 15:58                       ` Eli Zaretskii
  1 sibling, 0 replies; 25+ messages in thread
From: Jason Rumney @ 2003-10-22 11:15 UTC (permalink / raw)
  Cc: emacs-devel

Peter 'Luna' Runestig wrote:
> Hi all! Is there anything more I should do to get this patch accepted?
> When it comes to the issue about calling default-printer-name each time
> we print something, I can see several options:
> 
> o Leave as is (my favorite).
> o Only call default-printer-name on start-up.
> o Make the use of the above two ways run-time configurable.
> o Add some caching functionality to default-printer-name, and trigger
>   the "cache update" on WM_SETTINGCHANGE.

I favour the first option too. Worrying about a few milliseconds 
overhead for a system call on an operation like printing, that takes 
orders of magnitude longer, is not worth it IMHO. Caching would make the 
code overly complicated and difficult to maintain.

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

* Re: Windows port: using Windows' default printer
  2003-10-22 10:35                     ` Peter 'Luna' Runestig
  2003-10-22 11:15                       ` Jason Rumney
@ 2003-10-22 15:58                       ` Eli Zaretskii
  2003-11-26 11:55                         ` Peter 'Luna' Runestig
  1 sibling, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2003-10-22 15:58 UTC (permalink / raw)
  Cc: emacs-devel

> Date: Wed, 22 Oct 2003 12:35:13 +0200
> From: "Peter 'Luna' Runestig" <peter@runestig.com>
> 
> o Leave as is (my favorite).
> o Only call default-printer-name on start-up.
> o Make the use of the above two ways run-time configurable.
> o Add some caching functionality to default-printer-name, and trigger
>   the "cache update" on WM_SETTINGCHANGE.

I've voiced my opinion (for the second option), but if Jason and
others think the first option is better, I won't object.

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

* Re: Windows port: using Windows' default printer
  2003-10-22 15:58                       ` Eli Zaretskii
@ 2003-11-26 11:55                         ` Peter 'Luna' Runestig
  0 siblings, 0 replies; 25+ messages in thread
From: Peter 'Luna' Runestig @ 2003-11-26 11:55 UTC (permalink / raw)


On 2003-10-22 17:58, Eli Zaretskii wrote:
>> Date: Wed, 22 Oct 2003 12:35:13 +0200
>> From: "Peter 'Luna' Runestig" <peter@runestig.com>
>> 
>> o Leave as is (my favorite).
>> o Only call default-printer-name on start-up.
>> o Make the use of the above two ways run-time configurable.
>> o Add some caching functionality to default-printer-name, and trigger
>>   the "cache update" on WM_SETTINGCHANGE.
> 
> I've voiced my opinion (for the second option), but if Jason and
> others think the first option is better, I won't object.

Maybe it can be comitted then...?

-- 
Peter 'Luna' Runestig (fd. Altberg), Sweden <peter@runestig.com>
PGP Key ID: 0xD07BBE13
Fingerprint: 7B5C 1F48 2997 C061 DE4B  42EA CB99 A35C D07B BE13
AOL Instant Messenger Screen name: PRunestig
Yahoo! Messenger profile name: altberg

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

end of thread, other threads:[~2003-11-26 11:55 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-20 13:18 Windows port: using Windows' default printer Peter 'Luna' Runestig
2003-02-20 23:05 ` Jason Rumney
2003-02-21  6:52   ` Peter 'Luna' Runestig
2003-02-21  8:20     ` Jason Rumney
2003-09-12 19:34       ` Peter 'Luna' Runestig
2003-09-13 10:04         ` Eli Zaretskii
2003-09-13 10:35           ` Jason Rumney
2003-09-13 14:39             ` Eli Zaretskii
2003-09-13 19:44               ` Peter 'Luna' Runestig
2003-09-13 20:32                 ` Kai Grossjohann
2003-09-13 22:13                   ` Jason Rumney
2003-09-13 23:44                 ` Eli Zaretskii
2003-09-14  9:40                   ` Peter 'Luna' Runestig
2003-09-15 14:52         ` Stefan Monnier
2003-09-21 13:19           ` Eli Zaretskii
2003-09-21 19:51             ` Stefan Monnier
2003-09-22  6:07               ` Eli Zaretskii
2003-09-23 16:28               ` Peter 'Luna' Runestig
2003-09-24 18:25                 ` Eli Zaretskii
2003-09-24 19:22                   ` Luc Teirlinck
2003-09-25 13:26                   ` Peter 'Luna' Runestig
2003-10-22 10:35                     ` Peter 'Luna' Runestig
2003-10-22 11:15                       ` Jason Rumney
2003-10-22 15:58                       ` Eli Zaretskii
2003-11-26 11:55                         ` Peter 'Luna' Runestig

Code repositories for project(s) associated with this public inbox

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

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).