[sisyphus] vim+ruby

Alexander Bokovoy =?iso-8859-1?q?a=2Ebokovoy_=CE=C1_sam-solutions=2Enet?=
Пт Ноя 2 12:57:43 MSK 2001


On Fri, Nov 02, 2001 at 09:38:30AM +0600, Eugeny Korekin wrote:
> Может быть можно было бы собирать vim, который с --features=huge еще и с
> поддержкой ruby по умолчанию, раз уж ruby есть в sisyphus? Чем ruby хуже
> perl и python? %)
:-) Ничем не хуже. Особенно, если учесть, что интенсивность проникновения
Ruby в Сизиф скоро усилится (сюрприз :).

2Sergei Aranovsky: было бы очень хорошо его туда добавить, в виде
--enable-rubyinterp, тогда можно будет внутри VIM скрипты писать на Ruby
для самого редактора. Дополнительно, было бы хорошо добавить в runtimepath
http://vim.sourceforge.net/scripts/script.php?script_id=119
и http://users.erols.com/astronaut/vim/syntax/vim.vim.gz
а также приаттаченный скрит, для более полноценной поддержки встроенных
языков и выравнивания программ на них.
-- 
/ Alexander Bokovoy
$ cat /proc/identity >~/.signature
  `Senior software developer and analyst for SaM-Solutions Ltd.`
---
Xerox your lunch and file it under "sex offenders"!
----------- следующая часть -----------
>From ruby-talk-admin на ruby-lang.org  Sat Oct 27 11:18:47 2001
Return-Path: <ruby-talk-admin на ruby-lang.org>
Delivered-To: ab на localhost.belcaf.minsk.by
Received: from localhost (localhost.localdomain [127.0.0.1])
	by pc152.belcaf.minsk.by (Postfix) with ESMTP id 7D1A61CB
	for <ab на localhost>; Sat, 27 Oct 2001 11:18:47 +0300 (EEST)
Received: from 217.21.35.41 [217.21.35.41]
	by localhost with IMAP (fetchmail-5.9.0)
	for ab на localhost (single-drop); Sat, 27 Oct 2001 11:18:47 +0300 (EEST)
Received: from helium.ruby-lang.org ([210.251.121.214]) by
          mail.belcaf.minsk.by (Netscape Messaging Server 4.15) with ESMTP
          id GLUV1S00.MAW for <a.bokovoy на sam-solutions.net>; Sat, 27 Oct
          2001 11:17:52 +0300 
Received: from helium.ruby-lang.org (localhost [127.0.0.1])
	by helium.ruby-lang.org (Postfix) with ESMTP
	id B0B543C94; Sat, 27 Oct 2001 17:17:35 +0900 (JST)
Received: from mail.whidbey.net (mailout.whidbey.net [209.166.64.124])
	by helium.ruby-lang.org (Postfix) with SMTP id 7BFAA3B6F
	for <ruby-talk на ruby-lang.org>; Sat, 27 Oct 2001 17:17:34 +0900 (JST)
Received: (qmail 21431 invoked from network); 27 Oct 2001 08:17:33 -0000
Received: from unknown (HELO there) (208.31.145.234)
  by mail2.whidbey.net with SMTP; 27 Oct 2001 08:17:33 -0000
Date: Sat, 27 Oct 2001 17:17:35 +0900
Posted: Sat, 27 Oct 2001 01:20:26 -0700
From: Ned Konz <ned на bike-nomad.com>
Reply-To: ruby-talk на ruby-lang.org
Subject: [ruby-talk:23609] Re: ANN: RuEdit - introspective Ruby editor
To: ruby-talk на ruby-lang.org (ruby-talk ML)
Message-Id: <20011027081734.7BFAA3B6F на helium.ruby-lang.org>
In-Reply-To: <9r7old$opq$1 на wanadoo.fr>
References: <63604d2.0110190851.76343af на posting.google.com> <20011023.140232.238962600.7016 на zipworld.com.au> <9r7old$opq$1 на wanadoo.fr>
X-ML-Name: ruby-talk
X-Mail-Count: 23609
X-MLServer: fml [fml 3.0pl#17]; post only (anyone can post)
X-ML-Info: If you have a question, send e-mail with the body
	"help" (without quotes) to the address ruby-talk-ctl на ruby-lang.org;
	help=<mailto:ruby-talk-ctl на ruby-lang.org?body=help>
X-Mailer: KMail [version 1.3.1]
X-Image-URL: http://bike-nomad.com/nedicon.jpg
Mime-Version: 1.0
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
Precedence: bulk
Status: RO
Content-Length: 2321
Lines: 78

On Wednesday 24 October 2001 06:12 pm, Benoit Cerrina wrote:
> > One thing I'm thinking about is something that would allow a keystroke to
> > open up myri (not sure whether it's still called that ... the GUI someone
> > wrote to sit on top of the interactive reference) to the right entry for
> > the function or class my cursor's on.
>
> Don't know how myri works but I'd say its probably easier to do it without
> ruby.
> I believe doing something with another scripting language than vim's own
> is really usefull only when the something either:
>     needs data structures
>     is computationaly intensive
> none of this apply there.
> Benoit

Well, here's my first usage of Ruby inside of Vim. It implements a state 
machine that pulls out some but not all lines from one buffer into another, 
then reformats them so that adjacent blocks have single blank lines between 
them.

It was really annoying (and slow) to do in Vim because you have to explicitly 
switch between the buffers for every line.

I did use the Vim reformatting command, though, because it's faster and 
simpler for this task.

" Ruby function embedded in a Vim macro
function! OtlMakeText()
ruby <<EOF
  origBuffer = $curbuf
  lastLeader = nil
  lastWasBlank = true
  lastIndent = 0
  VIM::command("new")   # make a new window and switch to it
  newLine = 0

  (1 .. origBuffer.length).each { |n|
    line = origBuffer[n]
    indent = 0
    line.sub!(/^\t*/) { |tabs| indent = tabs.length; "" }
    if line =~ /^[|* 0-9-]/
      leader = line[0,1]
      line.sub!(/^\| /, "")
      if ((lastLeader \
          && leader != " " \
          && leader != lastLeader) \
            || indent != lastIndent)
        $curbuf.append(newLine, "")
        newLine = newLine+1
        lastWasBlank = true
      end
    else
      leader = nil
      line = ""
    end

    isBlank = (line == "")
    unless isBlank && lastWasBlank
      $curbuf.append(newLine, line)
      newLine = newLine+1
    end

    lastWasBlank = isBlank
    lastLeader = leader
    lastIndent = indent
  }

  VIM::command("set tw=80")     # set textwidth
  VIM::command("normal 1GgqG")  # re-format buffer
  VIM::command("wincmd p")      # return to last window
EOF
endfunction

-- 
Ned Konz
currently: Stanwood, WA
email:     ned на bike-nomad.com
homepage:  http://bike-nomad.com



Подробная информация о списке рассылки Sisyphus