zsh-users
 help / color / mirror / code / Atom feed
* Textfile-Favoring Completion
@ 2006-03-25 18:16 Chris Johnson
  2006-03-26  7:18 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Chris Johnson @ 2006-03-25 18:16 UTC (permalink / raw)
  To: zsh-users

A while back I posted about trying to complete only text files for vi,
vim, and emacs.  I'd had the problem of opening executable files instead
of the longer named source files (app versus app.c).  Bart and Peter
offered some good suggestions, but for one reason or another, nothing's
worked out perfect.  I think Peter suggested this one:

   # First match files that end in known text file extensions or are
   # directories.  Failing that, match anything.
   zstyle ':completion:*:*:(emacs|vi|vim):*' file-patterns \
          '*.(c|h|pl|tex|txt|cpp|java|php|bib):globbed-files
          *(-/):directories' \
          '*:all-files'

This one works okay, but that regular expression which details all known
text files becomes unwieldy.  Dotfiles aren't currently matched with
that pattern.  I thought I'd lost my .muttrc once because only my .mutt
directory would complete.  Completion has minimized my usage of ls, and
this can get me in trouble.  Bart offered a solution that fixed this and
was almost always right on target, scanning the result of the UNIX file
utility for the word 'text'.  This was a little slow, however:

   textfiles() {
      reply=( ${${(@M)${(f)"$(file $REPLY 2>/dev/null)"}\:#*text*}%:*} )
   }
   zstyle ':completion:*:*:(emacs|vi|vim):*' file-patterns \
          '%p(e,textfiles,):globbed-files *(-/):directories' \
          '*:all-files' 

Now I'm using something slightly simpler that has the same drawback as
the first solution in hiding certain files when there's a valid match in
the first group.  (For instance, I want to complete an executable plain
file 'itself.sh' but there's a directory 'include' that supercedes.)  It
does cut back on the regular expression maintenance, though.  (I haven't
entered the extensions for LaTeX yet, so this may change.)

   # First match files that aren't plain executable files or don't
   # end in .o.  Failing that, match anything.
   zstyle ':completion:*:*:(emacs|vi|vim):*' file-patterns \
          '*~*.o(^*):globbed-files' '*:all-files'

Just thought I'd share.  Someone posted something similar specifically
about LaTeX a few weeks ago which caused me to revisit the issue.

-- 
Chris Johnson
cjohnson@cs.utk.edu
http://www.cs.utk.edu/~cjohnson


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

* Re: Textfile-Favoring Completion
  2006-03-25 18:16 Textfile-Favoring Completion Chris Johnson
@ 2006-03-26  7:18 ` Bart Schaefer
  2006-03-26 18:59   ` zzapper
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2006-03-26  7:18 UTC (permalink / raw)
  To: zsh-users

On Mar 25,  1:16pm, Chris Johnson wrote:
}
} Now I'm using something slightly simpler that has the same drawback as
} the first solution in hiding certain files when there's a valid match in
} the first group.  (For instance, I want to complete an executable plain
} file 'itself.sh' but there's a directory 'include' that supercedes.)  It
} does cut back on the regular expression maintenance, though.  (I haven't
} entered the extensions for LaTeX yet, so this may change.)
} 
}    # First match files that aren't plain executable files or don't
}    # end in .o.  Failing that, match anything.
}    zstyle ':completion:*:*:(emacs|vi|vim):*' file-patterns \
}           '*~*.o(^*):globbed-files' '*:all-files'

If you're going to go about it that way, look at ignored-patterns:

zstyle ':completion:*:*:(emacs|vi|vim):*' ignored-patterns '*.o'

You may find it easier to maintain the list of excluded patterns there.
The drawback to ignored-patterns is that they're matched only against
the text of the file name, not used as file globs, so you can't, e.g.,
ignore files with the execute bit set.  However, if you combine it
with a variant of your file-patterns style ...

zstyle ':completion:*:*:(emacs|vi|vim):*' file-patterns \
    '*(.^*):globbed-files *(/):directories' '*:all-files'

... you may get something very close to what you want.

Just remember that you may also want to put _ignored into your completer
style somewhere.


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

* Re: Textfile-Favoring Completion
  2006-03-26  7:18 ` Bart Schaefer
@ 2006-03-26 18:59   ` zzapper
  0 siblings, 0 replies; 3+ messages in thread
From: zzapper @ 2006-03-26 18:59 UTC (permalink / raw)
  To: zsh-users




Tangential to OP

in your .vimrc

autocmd BufReadPost *.doc %!antiword "%"

This allows you to VIM a ms-word document obviously in READ-ONLY mode


(just to highlight a case when you might want to VIM a non-text file)



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

end of thread, other threads:[~2006-03-26 18:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-25 18:16 Textfile-Favoring Completion Chris Johnson
2006-03-26  7:18 ` Bart Schaefer
2006-03-26 18:59   ` zzapper

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

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).