Re: [Patch] Adapted :buffer listing

2006-12-27 Thread Simon Pamies
* Simon Pamies wrote, On 27.12.2006 11:50 Uhr:
 Hi All,
 
 I had some problems using the :buffer listing. If you have many files
 (read 30+) open, the :buffer list is cluttered up with long directory
 names (especially if working with files scattered over many directories)
 and you loose overview. Switching to another buffer can be a real pain
 especially because the completion completes on directory names. If you
 have directories named like files then you're typing stuff w/o getting
 to your file.

I just discovered a bug introduced shortly before creating the diffs: If
hitting WCHAR after menu is shown, completion will still take
directories. Will fix that in the next few days.

Simon Pamies



RE: [Patch] Adapted :buffer listing

2006-12-27 Thread Suresh Govindachar


   Simon Pamies Sent: Wednesday, December 27, 2006 3:19 AM
  * Simon Pamies wrote, On 27.12.2006 11:50 Uhr:
   Hi All,
   
   I had some problems using the :buffer listing. If you have many
   files (read 30+) open, the :buffer list is cluttered up with

  I usually have over 100 buffers, and have no problems with
  the existing support for buffers. 

   long directory names (especially if working with files
   scattered over many directories) and you loose overview.

  It is possible to write a plugin to list buffers sorted by
  name (http://www.vim.org/tips/tip.php?tip_id=976) -- but this is
  not really needed most of the time!

   Switching to another buffer can be a real pain especially
   because the completion completes on directory names. 
  
  Don't see what the problem is.  The following

   :b partial tab 
   
  works fine for me.

   If you have directories named like files then you're typing
   stuff w/o getting to your file.
  
   I just discovered a bug introduced shortly before creating the
   diffs: If hitting WCHAR after menu is shown, completion will
   still take directories. Will fix that in the next few days.

  Better to do such customizations as a plugin rather than patch the
  sources.  

  --Suresh 



Re: [Patch] Adapted :buffer listing

2006-12-27 Thread Simon Pamies
* Suresh Govindachar wrote, On 27.12.2006 12:35 Uhr:
 
Simon Pamies Sent: Wednesday, December 27, 2006 3:19 AM
   * Simon Pamies wrote, On 27.12.2006 11:50 Uhr:
Hi All,

I had some problems using the :buffer listing. If you have many
files (read 30+) open, the :buffer list is cluttered up with
 
   I usually have over 100 buffers, and have no problems with
   the existing support for buffers. 

/me has :-)

 
Switching to another buffer can be a real pain especially
because the completion completes on directory names. 
   
   Don't see what the problem is.  The following
 
:b partial tab 

   works fine for me.

try the following:
:b bach TAB
/home/spamies/work/bachl/bsc.cls /home/spamies/work/bachl/bach.tex

It tries to complete the work/bachl directory but I want it to complete
directly to bach.tex

   Better to do such customizations as a plugin rather than patch the
   sources.  

Thx for the suggestion - I mailed recently with some other vim-people
that said from themselves to have great experience in writing vim
plugins and they couldn't help me. So I started to adapt sourcecode.

I saw your code and now I'm not so sure anymore that adapting sourcecode
was such a good idea :-) But I'm not sure if one could solve the
completion problem (see above) using plugins...

Simon Pamies



Re: [Patch] Adapted :buffer listing

2006-12-27 Thread Simon Pamies
* Simon Pamies wrote, On 27.12.2006 12:19 Uhr:
 * Simon Pamies wrote, On 27.12.2006 11:50 Uhr:
 Hi All,

 I had some problems using the :buffer listing. If you have many files
 (read 30+) open, the :buffer list is cluttered up with long directory
 names (especially if working with files scattered over many directories)
 and you loose overview. Switching to another buffer can be a real pain
 especially because the completion completes on directory names. If you
 have directories named like files then you're typing stuff w/o getting
 to your file.
 
 I just discovered a bug introduced shortly before creating the diffs: If
 hitting WCHAR after menu is shown, completion will still take
 directories. Will fix that in the next few days.

Regardless if I'll find a possibility to implement this using plugins
here the fixed code (buffer.c.diff, others remain unchanged). Works for me.

Simon Pamies
Index: buffer.c
===
--- buffer.c(revision 195)
+++ buffer.c(working copy)
@@ -47,6 +47,7 @@
 static voidfree_buffer __ARGS((buf_T *));
 static voidfree_buffer_stuff __ARGS((buf_T *buf, int free_options));
 static voidclear_wininfo __ARGS((buf_T *buf));
+int fill_shortnames __ARGS(());
 
 #ifdef UNIX
 # define dev_T dev_t
@@ -221,6 +222,11 @@
 foldUpdateAll(curwin);
 #endif
 
+/* spamsch: Trigger setting of shortname but only
+ * option emacsbuflist is set */
+if (p_embl)
+fill_shortnames();
+
 #ifdef FEAT_AUTOCMD
 /* need to set w_topline, unless some autocommand already did that. */
 if (!(curwin-w_valid  VALID_TOPLINE))
@@ -449,6 +455,7 @@
 #endif
vim_free(buf-b_ffname);
vim_free(buf-b_sfname);
+vim_free(buf-b_sname);
if (buf-b_prev == NULL)
firstbuf = buf-b_next;
else
@@ -1569,6 +1576,8 @@
buf-b_ffname = NULL;
vim_free(buf-b_sfname);
buf-b_sfname = NULL;
+vim_free(buf-b_sname);
+buf-b_sname = NULL;
if (buf != curbuf)
free_buffer(buf);
return NULL;
@@ -1992,6 +2001,7 @@
 intdiffmode;   /* find diff-mode buffers only */
 {
 buf_T  *buf;
+buf_T   *sbuf;
 regprog_T  *prog;
 intmatch = -1;
 intfind_listed;
@@ -2059,7 +2069,22 @@
{
if (match = 0) /* already found a match */
{
-   match = -2;
+
+/* spamsch: This case can happen if the 
+ * short buffer name is used and we have
+ * two buffers with the same name. But because
+ * only one buffer shortname can match exactly
+ * the given one we check the buffer names
+ * for an exact match. */
+match = -2;
+
+if (p_embl) /* Check only if option is set */
+for (sbuf = firstbuf; sbuf != NULL; sbuf = 
sbuf-b_next)
+if (STRCMP(sbuf-b_sname, pattern) == 0) {
+match = sbuf-b_fnum;
+break;
+}
+
break;
}
match = buf-b_fnum;/* remember first match */
@@ -2088,12 +2113,71 @@
 }
 #endif
 
+/*
+ * spamsch: Go through the buffer list and fill
+ * the field b_sname for each buffer
+ */
+int
+fill_shortnames()
+{
+buf_T   *buf;
+buf_T   *sbuf;
+char_u  *pos;
+int counter;
+int fcounter;
+
+counter = fcounter = 0;
+for (buf = firstbuf; buf != NULL; buf = buf-b_next) {
+
+buf-b_sname = NULL;
+
+if (buf-b_ffname != NULL  buf-b_p_bl) {
+counter++;
+
+/* We want to have the filename so we search for
+ * the last slash and get stuff behind it */
+pos = vim_strrchr(buf-b_ffname, '/');
+
+char_u *cpstr;
+cpstr = (char_u *)alloc(255 * sizeof(char_u));
+if (cpstr == NULL)
+return FAIL;
+
+if (pos != NULL) {
+vim_strncpy(cpstr, pos+1, (unsigned)STRLEN(pos)-1);
+
+for (sbuf = firstbuf; sbuf != NULL; sbuf = sbuf-b_next)
+if (buf != sbuf)
+if (sbuf-b_sname != NULL)
+if (STRCMP(sbuf-b_sname, cpstr) == 0) {
+char bnamenum[255];
+sprintf(bnamenum, %d, ++fcounter);
+STRCAT(cpstr, bnamenum);
+break;
+}
+
+} else {
+STRCPY(cpstr, 

RE: [Patch] Adapted :buffer listing

2006-12-27 Thread Suresh Govindachar

   Simon Pamies Sent: Wednesday, December 27, 2006 3:49 AM
  * Suresh Govindachar wrote, On 27.12.2006 12:35 Uhr:
   Simon Pamies Sent: Wednesday, December 27, 2006 3:19 AM
  * Simon Pamies wrote, On 27.12.2006 11:50 Uhr:
  
  [...]
  
   try the following:
   :b bach TAB
   /home/spamies/work/bachl/bsc.cls /home/spamies/work/bachl/bach.tex
   
   It tries to complete the work/bachl directory but I want it to
   complete directly to bach.tex
  
   Better to do such customizations as a plugin rather than
   patch the sources.  
  
   Thx for the suggestion - I mailed recently with some other
   vim-people that said from themselves to have great experience in
   writing vim plugins and they couldn't help me. So I started to
   adapt sourcecode.
  
   I saw your code and now I'm not so sure anymore that adapting
   sourcecode was such a good idea :-) But I'm not sure if one
   could solve the completion problem (see above) using plugins...

  See 

 help :command-completion

  It is not that complicated.  Essentially, when user types
:B bach tab
  your custom completion function will be called with argument bach;
  your custom completion function will need to look at the list of
  buffers and select those which have bach in their file-name and
  return the selected sub-list of buffers.
  
  --Suresh
   



Re: [Patch] Adapted :buffer listing

2006-12-27 Thread Simon Pamies
* Suresh Govindachar wrote, On 27.12.2006 14:42 Uhr:
Simon Pamies Sent: Wednesday, December 27, 2006 3:49 AM
   * Suresh Govindachar wrote, On 27.12.2006 12:35 Uhr:
Simon Pamies Sent: Wednesday, December 27, 2006 3:19 AM
   * Simon Pamies wrote, On 27.12.2006 11:50 Uhr:
   
   [...]
   
try the following:
:b bach TAB
/home/spamies/work/bachl/bsc.cls /home/spamies/work/bachl/bach.tex

It tries to complete the work/bachl directory but I want it to
complete directly to bach.tex
[...]
   See 
 
  help :command-completion
 
   It is not that complicated.  Essentially, when user types
 :B bach tab
   your custom completion function will be called with argument bach;
   your custom completion function will need to look at the list of
   buffers and select those which have bach in their file-name and
   return the selected sub-list of buffers.

That's great - I should have asked this list before! Thanks for the
hint! If I find time I'll rewrite my stuff as plugin. Until then I'll
use my patched vim.

Simon