WinHugs, sensible defaults (II)

Neil Mitchell <[email protected]>
Newsgroups gmane.comp.lang.haskell.cvs.hugs
Message-ID <[email protected]>
Hi,

At the moment, WinHugs defaults to notepad as the editor. Notepad
cannot open a specific line or char, which means its not great for
using with WinHugs, much of the impressive bits of WinHugs become less
useful.

This patch makes it use any editor but notepad if it can find one,
otherwise notepad. With this patch, and the auto-reload files one
(sent previously) it would mean that the average WinHugs user does not
need a trip to the options dialog before they are running WinHugs at
its optimum.

Thanks

Neil

_______________________________________________
Cvs-hugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-hugs
editor-default.patch (application/octet-stream, 1.9 KB)
Index: src/hugs.c
===================================================================
RCS file: /cvs/hugs98/src/hugs.c,v
retrieving revision 1.144
diff -u -r1.144 hugs.c
--- src/hugs.c	6 Sep 2005 19:48:29 -0000	1.144
+++ src/hugs.c	16 Sep 2005 16:30:11 -0000
@@ -89,6 +89,9 @@
      */
     hugsEdit      = strCopy(fromEnv("EDITOR",NULL));
     if (hugsEdit == NULL) {
+#if HUGS_FOR_WINDOWS
+		hugsEdit = WinHugsPickDefaultEditor();
+#else
       UINT rc;
       int notePadLen = strlen(DEFAULT_EDITOR);
       char* notePadLoc;
@@ -112,6 +115,7 @@
 	strcat(notePadLoc, DEFAULT_EDITOR);
 	hugsEdit = strCopy(notePadLoc);
       }
+#endif
     }
 #elif __MWERKS__ && macintosh
     hugsEdit      = NULL;
Index: src/winhugs/Editors.c
===================================================================
RCS file: /cvs/hugs98/src/winhugs/Editors.c,v
retrieving revision 1.1
diff -u -r1.1 Editors.c
--- src/winhugs/Editors.c	6 Sep 2005 10:49:26 -0000	1.1
+++ src/winhugs/Editors.c	16 Sep 2005 16:29:38 -0000
@@ -96,3 +96,20 @@
         Buffer[0] = 0;
     return Editors[Index].Name;
 }
+
+char* WinHugsPickDefaultEditor()
+{
+	TCHAR Buffer[MAX_PATH];
+	int i;
+	for (i = 1; ; i++)
+	{
+		LPCTSTR x = GetEditor(i, Buffer);
+		if (x == NULL) break;
+		if (Buffer[0] != 0) return strdup(Buffer);
+	}
+	GetEditor(0, Buffer);
+	if (Buffer[0] == 0)
+		return NULL;
+	else
+		return strdup(Buffer);
+}
Index: src/winhugs/Winhugs.h
===================================================================
RCS file: /cvs/hugs98/src/winhugs/Winhugs.h,v
retrieving revision 1.14
diff -u -r1.14 Winhugs.h
--- src/winhugs/Winhugs.h	8 Sep 2005 16:02:03 -0000	1.14
+++ src/winhugs/Winhugs.h	16 Sep 2005 16:24:48 -0000
@@ -10,6 +10,8 @@
 extern void	ErrorBox(const char* Msg);
 extern void	InfoBox(const char* Msg);
 
+extern char* WinHugsPickDefaultEditor();
+
 extern void	WinHugsExit(void);
 
 extern int	InAutoReloadFiles;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.