[PATCH] Let synIDattr() query guifg/bg/sp without +gui

2009-03-27 Fir de Conversatie Matt Wozniski
Currently, in a vim that isn't built with +gui, it's possible to set the
gui, guifg, guibg, and guisp attributes for a highlight group, but not
to retrieve those settings - the command is accepted with no error, but
the settings are silently ignored.  This is unfortunate, since scripts
might want to query what colors would be being used if a gui were
running.  One example is CSApprox.vim, which needs to know what colors
would be being used in the gui in order to pick and set the closest
available terminal colors.

This patch allows synIDattr() to report the gui, guifg, guibg, and guisp
attributes even when vim isn't compiled with +gui.  It should be
uncontroversial; it only changes some #ifdef's around so that things
that were only stored when +gui before are now stored when either +gui
or +eval.  In my testing, it makes CSApprox work perfectly in gui-less
vim versions.

~Matt


--~--~-~--~~~---~--~~
You received this message from the vim_dev maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---

commit e458c019b0ff0515259aebca8e04ce06b9a2646c
Author: Matt Wozniski m...@drexel.edu
Date:   Fri Mar 27 02:15:31 2009 -0400

Let synIDattr() query guifg/bg/sp without +gui

diff --git a/src/eval.c b/src/eval.c
index 98979b1..ce50aef 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -16629,9 +16629,7 @@ f_synIDattr(argvars, rettv)
 	mode = get_tv_string_buf(argvars[2], modebuf);
 	modec = TOLOWER_ASC(mode[0]);
 	if (modec != 't'  modec != 'c'
-#ifdef FEAT_GUI
 		 modec != 'g'
-#endif
 		)
 	modec = 0;	/* replace invalid with current */
 }
diff --git a/src/syntax.c b/src/syntax.c
index 4b4b0bb..e4d0089 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -48,6 +48,13 @@ struct hl_group
 #endif
 char_u	*sg_font_name;  /* GUI font or fontset name */
 int		sg_gui_attr;/* Screen attr for GUI mode */
+#else
+# ifdef FEAT_EVAL
+int		sg_gui;		/* gui= highlighting attributes */
+char_u	*sg_gui_fg_name;/* GUI foreground color name */
+char_u	*sg_gui_bg_name;/* GUI background color name */
+char_u	*sg_gui_sp_name;/* GUI special color name */
+# endif
 #endif
 int		sg_link;	/* link to this highlight group ID */
 int		sg_set;		/* combination of SG_* flags */
@@ -6203,7 +6210,7 @@ syn_get_foldlevel(wp, lnum)
  * The #ifdefs are needed to reduce the amount of static data.  Helps to make
  * the 16 bit DOS (museum) version compile.
  */
-#ifdef FEAT_GUI
+#if defined(FEAT_GUI) || defined(FEAT_EVAL)
 # define CENT(a, b) b
 #else
 # define CENT(a, b) a
@@ -6923,7 +6930,7 @@ do_highlight(line, forceit, init)
 		HL_TABLE()[idx].sg_cterm_bold = FALSE;
 		}
 	}
-#ifdef FEAT_GUI
+#if defined(FEAT_GUI) || defined(FEAT_EVAL)
 	else
 	{
 		if (!init || !(HL_TABLE()[idx].sg_set  SG_GUI))
@@ -7221,6 +7228,20 @@ do_highlight(line, forceit, init)
 # endif
 		}
 	}
+#else
+# ifdef FEAT_EVAL   /* Store the fg color name for synIDattr() */
+	if (!init || !(HL_TABLE()[idx].sg_set  SG_GUI))
+	{
+		if (!init)
+		HL_TABLE()[idx].sg_set |= SG_GUI;
+
+		vim_free(HL_TABLE()[idx].sg_gui_fg_name);
+		if (STRCMP(arg, NONE))
+		HL_TABLE()[idx].sg_gui_fg_name = vim_strsave(arg);
+		else
+		HL_TABLE()[idx].sg_gui_fg_name = NULL;
+	}
+# endif
 #endif
 	}
 	else if (STRCMP(key, GUIBG) == 0)
@@ -7253,6 +7274,20 @@ do_highlight(line, forceit, init)
 # endif
 		}
 	}
+#else
+# ifdef FEAT_EVAL   /* Store the bg color name for synIDattr() */
+	if (!init || !(HL_TABLE()[idx].sg_set  SG_GUI))
+	{
+		if (!init)
+		HL_TABLE()[idx].sg_set |= SG_GUI;
+
+		vim_free(HL_TABLE()[idx].sg_gui_bg_name);
+		if (STRCMP(arg, NONE))
+		HL_TABLE()[idx].sg_gui_bg_name = vim_strsave(arg);
+		else
+		HL_TABLE()[idx].sg_gui_bg_name = NULL;
+	}
+# endif
 #endif
 	}
 	else if (STRCMP(key, GUISP) == 0)
@@ -7274,6 +7309,20 @@ do_highlight(line, forceit, init)
 			HL_TABLE()[idx].sg_gui_sp_name = NULL;
 		}
 	}
+#else
+# ifdef FEAT_EVAL   /* Store the sp color name for synIDattr() */
+	if (!init || !(HL_TABLE()[idx].sg_set  SG_GUI))
+	{
+		if (!init)
+		HL_TABLE()[idx].sg_set |= SG_GUI;
+
+		vim_free(HL_TABLE()[idx].sg_gui_sp_name);
+		if (STRCMP(arg, NONE))
+		HL_TABLE()[idx].sg_gui_sp_name = vim_strsave(arg);
+		else
+		HL_TABLE()[idx].sg_gui_sp_name = NULL;
+	}
+# endif
 #endif
 	}
 	else if (STRCMP(key, START) == 0 || STRCMP(key, STOP) == 0)
@@ -7503,17 +7552,19 @@ highlight_clear(idx)
 HL_TABLE()[idx].sg_cterm_fg = 0;
 HL_TABLE()[idx].sg_cterm_bg = 0;
 HL_TABLE()[idx].sg_cterm_attr = 0;
-#ifdef FEAT_GUI	/* in non-GUI fonts are simply ignored */
+#if defined(FEAT_GUI) || defined(FEAT_EVAL)
 HL_TABLE()[idx].sg_gui = 0;
-HL_TABLE()[idx].sg_gui_fg = INVALCOLOR;
 vim_free(HL_TABLE()[idx].sg_gui_fg_name);
 HL_TABLE()[idx].sg_gui_fg_name = NULL;
-HL_TABLE()[idx].sg_gui_bg = INVALCOLOR;
 

Re: Patch for ruby1.9 works with vim

2009-03-27 Fir de Conversatie Kessia 'even' Pinheiro
I forgot to attach the patch.

On Fri, Mar 27, 2009 at 3:29 PM, Kessia 'even' Pinheiro
kessiapinhe...@gmail.com wrote:
 Hi folks,
 I made a patch for VIM works with ruby1.9 and it are running fine
 here. It affects file if_ruby.c only. For who want compile it for
 ruby1.9, I need pass the library path for make with:

  make \
        CXXFLAGS=${CXXFLAGS} -I/usr/include/ruby-1.9.1/ \
                              -I/usr/include/ruby-1.9.1/i686-linux/ \
        CFLAGS=${CFLAGS} -I/usr/include/ruby-1.9.1/ \
                                  -I/usr/include/ruby-1.9.1/i686-linux/

 because some issues for ruby package.

 Please, tell me if some are wrong.
 --
 Kessia Pinheiro
 Computer Science Student - Brazil, UFBa
 Linux System Administrator
 Arch Linux Trusted User
 Linux User #389695
 http://even.archlinux-br.org
 ---
 X Fórum Internacional Software Livre - fisl10
 24 a 27 de junho de 2009
 PUCRS - Porto Alegre - Brasil




-- 
Kessia Pinheiro
Computer Science Student - Brazil, UFBa
Linux System Administrator
Arch Linux Trusted User
Linux User #389695
http://even.archlinux-br.org
---
X Fórum Internacional Software Livre - fisl10
24 a 27 de junho de 2009
PUCRS - Porto Alegre - Brasil

--~--~-~--~~~---~--~~
You received this message from the vim_dev maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---

--- src/if_ruby.c	2007-09-10 05:40:38.0 -0300
+++ src/if_ruby.new	2009-02-18 12:46:25.371757534 -0300
@@ -26,6 +26,7 @@
 # define RUBYEXTERN extern
 #endif
 
+#define HAVE_STRUCT_TIMESPEC
 /*
  * This is tricky.  In ruby.h there is (inline) function rb_class_of()
  * definition.  This function use these variables.  But we want function to
@@ -129,7 +130,8 @@
 #define rb_str_concat			dll_rb_str_concat
 #define rb_str_new			dll_rb_str_new
 #define rb_str_new2			dll_rb_str_new2
-#define ruby_errinfo			(*dll_ruby_errinfo)
+#define rb_errinfo  dll_rb_errinfo
+#define ruby_init_stack dll_ruby_init_stack
 #define ruby_init			dll_ruby_init
 #define ruby_init_loadpath		dll_ruby_init_loadpath
 #if defined(DYNAMIC_RUBY_VER)  DYNAMIC_RUBY_VER = 18
@@ -183,7 +185,8 @@
 static VALUE (*dll_rb_str_concat) (VALUE, VALUE);
 static VALUE (*dll_rb_str_new) (const char*, long);
 static VALUE (*dll_rb_str_new2) (const char*);
-static VALUE *dll_ruby_errinfo;
+static VALUE (*dll_rb_errinfo) (void);
+static void (*dll_ruby_init_stack) (void);
 static void (*dll_ruby_init) (void);
 static void (*dll_ruby_init_loadpath) (void);
 #if defined(DYNAMIC_RUBY_VER)  DYNAMIC_RUBY_VER = 18
@@ -245,7 +248,8 @@
 {rb_str_concat, (RUBY_PROC*)dll_rb_str_concat},
 {rb_str_new, (RUBY_PROC*)dll_rb_str_new},
 {rb_str_new2, (RUBY_PROC*)dll_rb_str_new2},
-{ruby_errinfo, (RUBY_PROC*)dll_ruby_errinfo},
+{rb_errinfo, (RUBY_PROC*)dll_rb_errinfo},
+{ruby_init_stack, (RUBY_PROC*)dll_ruby_init_stack},
 {ruby_init, (RUBY_PROC*)dll_ruby_init},
 {ruby_init_loadpath, (RUBY_PROC*)dll_ruby_init_loadpath},
 #if defined(DYNAMIC_RUBY_VER)  DYNAMIC_RUBY_VER = 18
@@ -413,7 +417,8 @@
 #ifdef DYNAMIC_RUBY
 	if (ruby_enabled(TRUE))
 	{
-#endif
+#endif
+RUBY_INIT_STACK
 	ruby_init();
 	ruby_init_loadpath();
 	ruby_io_init();
@@ -433,9 +438,6 @@
 
 static void error_print(int state)
 {
-#ifndef DYNAMIC_RUBY
-RUBYEXTERN VALUE ruby_errinfo;
-#endif
 VALUE eclass;
 VALUE einfo;
 char buff[BUFSIZ];
@@ -468,9 +470,9 @@
 	break;
 case TAG_RAISE:
 case TAG_FATAL:
-	eclass = CLASS_OF(ruby_errinfo);
-	einfo = rb_obj_as_string(ruby_errinfo);
-	if (eclass == rb_eRuntimeError  RSTRING(einfo)-len == 0) {
+	eclass = CLASS_OF(rb_errinfo());
+	einfo = rb_obj_as_string(rb_errinfo());
+	if (eclass == rb_eRuntimeError  RSTRING_LEN(einfo) == 0) {
 	EMSG(_(E272: unhandled exception));
 	}
 	else {
@@ -479,7 +481,7 @@
 
 	epath = rb_class_path(eclass);
 	vim_snprintf(buff, BUFSIZ, %s: %s,
-		 RSTRING(epath)-ptr, RSTRING(einfo)-ptr);
+		 RSTRING_PTR(epath), RSTRING_PTR(einfo));
 	p = strchr(buff, '\n');
 	if (p) *p = '\0';
 	EMSG(buff);
@@ -497,8 +499,8 @@
 char *buff, *p;
 
 str = rb_obj_as_string(str);
-buff = ALLOCA_N(char, RSTRING(str)-len);
-strcpy(buff, RSTRING(str)-ptr);
+buff = ALLOCA_N(char, RSTRING_LEN(str));
+strcpy(buff, RSTRING_PTR(str));
 p = strchr(buff, '\n');
 if (p) *p = '\0';
 MSG(buff);
@@ -886,10 +888,10 @@
 win_T *win = get_win(self);
 
 Check_Type(pos, T_ARRAY);
-if (RARRAY(pos)-len != 2)
+if (RARRAY_LEN(pos) != 2)
 	rb_raise(rb_eArgError, array length must be 2);
-lnum = RARRAY(pos)-ptr[0];
-col = RARRAY(pos)-ptr[1];
+lnum = RARRAY_PTR(pos)[0];
+col = RARRAY_PTR(pos)[1];
 win-w_cursor.lnum = NUM2LONG(lnum);
 win-w_cursor.col = NUM2UINT(col);
 check_cursor();		/* put cursor on an existing line */
@@ -906,7 +908,7 @@
 	if (i  0) 

Re: PATCH: Completion for find and sfind arguments (todo.txt)

2009-03-27 Fir de Conversatie Nazri Ramliy
On Fri, Mar 6, 2009 at 10:09 AM, Nazri Ramliy ayieh...@gmail.com wrote:
 On Thu, Mar 5, 2009 at 11:07 AM, Bram Moolenaar b...@moolenaar.net wrote:
 Cycles in symbolic links are rare.  The code should be able to handle
 this, in a way that it doesn't drop all results that contain a symbolic
 link.  Thus symbolic links should be followed, unless getting to a
 directory that was previously visited.

[snip]

 Anyway, the patch adds a lot of code.  I'm wondering if we can reuse
 more of the existing code.  How about using globpath()?  Or use
 find_file_in_path(), like ex_find() does (also accepting directories
 though).  The last one also takes care of removing duplicates.

 If your code is to be used, the chdir() calls are not safe.  Look at the
 mch_FullName() function in os_unix.c, lots of remarks about this.
 Yet another reason to use as much of the existing code, that has been
 debugged for a long time, instead of introducing new code which new
 problems.

[snip]

 Also, the functions potentially take a lot of time, so they should check
 for CTRL-C now and then.  That means calling ui_breakcheck() and
 checking the got_int flag.

[snip]

 There's a couple more issues that I found out while using :find with the
 patch:

1. It doesn't honor the 'wildignore' setting in cases where there
   are more than one files matching the pattern and at least one of
   them would be excluded by 'wildignore'. The current behavior is
   that it will list all the files that match the pattern whether or
   not it matches 'wildignore'.

2. Doing :find a/*/hello.html gets uniquefied to hello.html, which
   may not be what we want as there might be other hello.html in
   'path'.  The solution to this might be to uniquefy the name based
   on the pattern, not by the fullpath alone.

Here's the updated patch with all the above issues addressed:

1. Cycle resulting from symbolic links - I'm using globpath() and it
   seems that this is no longer an issue anymore.

2. No more chdir() calls.

3. Call to ui_breakcheck() is done and got_int flag is checked
   accordingly.

4. wildignore setting is already handled by globpath()

5. uniquefy_paths() uniquefies and shortens the fullpaths based on the
   given pattern. Please check up on the FIXME note that I added in the
   patch.

If anyone could test the patch on other OS that would be great. I've
tested it on my linux and all seemed well.

nazri

--~--~-~--~~~---~--~~
You received this message from the vim_dev maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---

Index: ex_docmd.c
===
--- ex_docmd.c	(revision 1425)
+++ ex_docmd.c	(working copy)
@@ -3422,6 +3422,11 @@
  */
 switch (ea.cmdidx)
 {
+	case CMD_find:
+	case CMD_sfind:
+	case CMD_tabfind:
+	xp-xp_context = EXPAND_FILES_IN_PATH;
+	break;
 	case CMD_cd:
 	case CMD_chdir:
 	case CMD_lcd:
Index: ex_getln.c
===
--- ex_getln.c	(revision 1425)
+++ ex_getln.c	(working copy)
@@ -4078,6 +4078,7 @@
 char_u	*tail;
 
 if (context != EXPAND_FILES
+	 context != EXPAND_FILES_IN_PATH
 	 context != EXPAND_SHELLCMD
 	 context != EXPAND_DIRECTORIES)
 {
@@ -4392,7 +4393,9 @@
 if (options  WILD_SILENT)
 	flags |= EW_SILENT;
 
-if (xp-xp_context == EXPAND_FILES || xp-xp_context == EXPAND_DIRECTORIES)
+if (xp-xp_context == EXPAND_FILES
+	|| xp-xp_context == EXPAND_DIRECTORIES
+	|| xp-xp_context == EXPAND_FILES_IN_PATH)
 {
 	/*
 	 * Expand file or directory names.
@@ -4422,6 +4425,8 @@
 
 	if (xp-xp_context == EXPAND_FILES)
 	flags |= EW_FILE;
+	else if (xp-xp_context == EXPAND_FILES_IN_PATH)
+	flags |= (EW_FILE | EW_PATH);
 	else
 	flags = (flags | EW_DIR)  ~EW_FILE;
 	ret = expand_wildcards(1, pat, num_file, file, flags);
Index: misc1.c
===
--- misc1.c	(revision 1425)
+++ misc1.c	(working copy)
@@ -9101,7 +9101,200 @@
 }
 #endif
 
+#if defined(FEAT_SEARCHPATH)
 /*
+ * Moves psep to the previous path separator in path, starting from the
+ * end of path. Returns FAIL is psep ends up at the beginning of path.
+ */
+static int
+find_previous_pathsep(path, psep)
+char_u *path;
+char_u **psep;
+{
+/* 
+ * As we're looking for the previous path separator, skip the current
+ * separator.
+ */ 
+if (vim_ispathsep(**psep))
+	(*psep)--;
+
+while (*psep = path  !vim_ispathsep(**psep))
+	(*psep)--;
+
+if (*psep != path  vim_ispathsep(**psep))
+	return OK;
+
+return FAIL;
+}
+
+/*
+ * Returns TRUE if maybe_unique is unique wrt other_paths in gap. maybe_unique
+ * is the end portion of ((char_u **)gap-ga_data)[i].
+ */
+static int
+is_unique(maybe_unique, gap, i)
+char_u	*maybe_unique;
+garray_T	*gap;
+

Strange behavior of 'wincmd'

2009-03-27 Fir de Conversatie Dasn

Commands like 'wincmd K', 'wincmd J', 'wincmd L' and 'wincmd H' can
be used to change the window layout, but sometimes they have strange
effects on the view of the other windows even if the whole windows
layout are not get changed. 

To make this problem reproduce-able, I wrote a test script for it. But
first, let me describe the script a little:

  The script simply creates 2 windows in Vim. One is called 'Main'(on
top) and the other is called 'Log'(on bottom). First, I append 100 lines
to 'Main', then goto 50th line and make this line displayed on the
bottom of the window by using 'zb'. Next, I switch to the 'Log' window,
move the window to bottom (although it's been already on the bottom) by
'wincmd J' and write a line into it. I noticed the problem: After
'wincmd J', the view of 'Main' window got changed (that is the 50th line
was moved to the top of 'Main'). I suppose it's a bug.

The following script was tested with: VIM - Vi IMproved 7.2-1-148, by
using command:
$ vim -u NONE -S test.vim

fun! BuildLines(prefix)
let a = []
for i in range(1, 100)
call add(a, a:prefix . : This is line  . i)
endfor
return a
endfun

fun! Test()
set equalalways
set scrolloff=0

 Create a Log window 
new Log
set bt=nofile
only!

 Create Main Window, then write some lines into it and 
 display the 50th line in the bottom of the window
top new Main
set bt=nofile

let a=BuildLines(Main)
call append(0, a)
normal 50G
normal zb
normal zz
 let win_save = winsaveview()
 call winrestview(win_save)

 Add some lines to another window (that is, the Log window)
let win_no = bufwinnr(Log)
if win_no != -1
 Found the Log window
exe win_no . wincmd w
wincmd J NOTE: This command will triger the problem
call append('$', Log: Where is the 50th line? )
exe normal G
endif
endfun

call Test()
redraw!


-- 
Dasn


--~--~-~--~~~---~--~~
You received this message from the vim_dev maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---