jed-users mailing list

[2005 Date Index] [2005 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: Update to my Jed macros page


On 13.10.05, Dave Kuhlman wrote:
> On Thu, Oct 13, 2005 at 09:05:11AM +0100, Peter Bengtsson wrote:
> > I've been using your search_current_word macro for a long time now and
> > find it very useful. I

> > ...if instead the current word is "get_foobar"
> > and I have the cursor between the two "o"'s, then what it searches for
> > is "foobar" only.
> > 
> > With my un-understanding of slang understand (at least) that it's not
> > your fault. The culprit is get_word() from txtutils.sl. Digging
> > deeping in txtutils I think the culprit is that stuff about Word_Chars
> > where I'm not totally lost.
>
> I believe that Word_Chars is local to to txtutils.sl.  Use
> define_word() instead.

No, Word_Chars is a buffer local variable: While define_word() defines
word chars globally (i.e. for all buffers and modes), the buffer local
variable allows different settings for different modes.

The "word determination algorithm" in txtutiols is 
(citing the doc for mark_word):

    Mark a word as visible region. 
    Get the idea of the characters a word is made of from (in order of 
    preference):
    
       * the optional argument `word_chars',
       * the buffer local variable "Word_Chars", or
       * the jed function `get_word_chars'.
    
    The optional argument `skip' tells how to skip non-word characters
    
      -1 skip backward
       0 don't skip (default)
       1 skip forward


So, e.g. I use in my .jedrc 

   define slang_mode_hook ()
   {
      define_blocal_var("Word_Chars", get_word_chars + "_");
      set_programming_keys();
      ...
   }
   
   define latex_mode_hook ()
   {
      set_comment_info ("TeX"    , "% "   , ""    , 2|4);
      set_comment_info ("LaTeX"  , "% "   , ""    , 2|4);
      define_blocal_var("Word_Chars", get_word_chars+"\\");

   ...
 
Beware: only the functions in txtutils.sl (and functions depending on
them) will honour the Word_Chars variable. 


> > PS. If the cursor is at the beginning of the word "this" of
> > "is_this_astring" and I press Ctrl-D to kill the forward word, then I
> > still want it only to delete the word "this" like my setup currently
> > allows.

> But, you are right, in that this causes skip_word, bskip_word, and
> kill_word to work across underscores.  

In this case, the non-awareness of standard functions to the buffer local
word might help you (I do not know what function Ctrl-D is bound to).


> To get the behavior you
> want, you can add something like the following at the beginning of
> search_current_word:
> 
>     define_word("A-Za-z0-9");
> 
> and this at the end:
> 
>     define_word("_A-Za-z0-9");

A better option in this case is to call mark_word() with the `word_chars'
argument in search_current_word():

-        word = get_word();
+        word = get_word("_A-Za-z0-9");

This is the quick fix, while 

 define_blocal_var("Word_Chars", <local word chars>);
 
in mode hooks is the more flexible one.


BTW: as a result of this discussion, I updated the documentation in 
     http://jedmodes.sf.net/mode/txtutils/ so hopefully it is now 
     easier to understand.


Guenter 

-- 
G.Milde web.de

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2005 date index] [2005 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]