[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RP] substring window matching
From: |
Björn Lindström |
Subject: |
Re: [RP] substring window matching |
Date: |
Thu May 22 14:41:03 2003 |
User-agent: |
Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux) |
Rupert Levene <address@hidden> writes:
> Give it a whirl, I think this one's actually quite useful! It lets you
> select windows based on substrings of their names rather than having
> to match stuff at the start of their names.
Isn't this better done in a script? Then you can for instance choose to
use RegExps, substrings or whatever the language in use supports.
Like I do for instance:
(When I did this I was running on tea alone, so it's optimised for
readability rather than speed.)
#!/usr/bin/env ruby
# Usage: select.rb MATCH NAME COMMAND
# Select the last accessed window matched by MATCH, or run COMMAND.
#
# .ratpoisonrc example: bind e exec select.rb '^(emacs@|Emacs:)' Emacs emacs
match = Regexp.new(ARGV[0])
name = ARGV[1]
command = ARGV[2]
fail "Too many arguments." if ARGV[3]
current = false # Set to true if the current window matches
matches = 0 # The number of windows that matches
windows = {} # A hash of windows indexed by ordering number
`ratpoison -c 'windows %n %s %l %t'`.split("\n").each { |window|
number, status, order, title = window.split(' ', 4)
if title =~ match
matches += 1
windows[order.to_i] = number.to_i
current = true if status == '*'
end
}
if matches > 1
if current
exec("ratpoison -c 'select #{windows[windows.keys.sort.reverse[1]]}'")
else
exec("ratpoison -c 'select #{windows[windows.keys.sort.reverse[0]]}'")
end
elsif matches == 1
if current
exec("ratpoison -c 'echo No other #{name} window'")
else
exec("ratpoison -c 'select #{windows[windows.keys.sort.reverse[0]]}'")
end
else
exec(command)
end