From: Franz Fellner Date: Fri, 10 Oct 2014 09:44:57 +0000 (+0200) Subject: Re: [PATCH] VIM: Add URI handling X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=20c60d48da5348616b118afb9726c9f2e5d02c3c;p=notmuch-archives.git Re: [PATCH] VIM: Add URI handling --- diff --git a/58/c35ae22993163700be3b0a35fdddbf6f2ec61c b/58/c35ae22993163700be3b0a35fdddbf6f2ec61c new file mode 100644 index 000000000..afb3d45ea --- /dev/null +++ b/58/c35ae22993163700be3b0a35fdddbf6f2ec61c @@ -0,0 +1,232 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 9AB4F431FBF + for ; Fri, 10 Oct 2014 02:44:58 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 7-SUdMkrZ39w for ; + Fri, 10 Oct 2014 02:44:51 -0700 (PDT) +Received: from mail-la0-f44.google.com (mail-la0-f44.google.com + [209.85.215.44]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 1C72E431FBC + for ; Fri, 10 Oct 2014 02:44:50 -0700 (PDT) +Received: by mail-la0-f44.google.com with SMTP id hs14so2835564lab.31 + for ; Fri, 10 Oct 2014 02:44:49 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=date:message-id:from:to:subject:in-reply-to:references:mime-version + :content-type:content-disposition:content-transfer-encoding; + bh=GDCdTPNQvzDxSo1TqZG1AmVGDq30JuUJ+4zfpXPSIn8=; + b=YeSO3XIlGc4UHcR0/iqu0rBC1KM1IzqNii3RnkNk8XSoSFhLxYVQm5HKdbqSMwi+dH + dQB3XJVSB0Ui/0ptnpnaAWnyKhNssK+6x1/hO0Yx02yEbtvw1p3IYezTdPB1wZpwxchr + fbYoKgVbOpHAg0BPiloTQsF299BwusXOKVHGfjUrLh5a6a77HDJG429bJN7Fek92GgFt + r65cI2Cs+YlH5UbtcvtUdQXpuYBfy/m4I3hVt/a95SCWGFmiNFxswQ/TCJnyCqrbJjfu + lH+CBRP9Q5yZPcMaqTgZ0ENi2tpRqODDMvoNcjZlq4SpSzac7ZIpXil/X3GyDwaqDbGq + OmEg== +X-Received: by 10.112.201.72 with SMTP id jy8mr3420236lbc.78.1412934289222; + Fri, 10 Oct 2014 02:44:49 -0700 (PDT) +Received: from localhost (p5B00C9E6.dip0.t-ipconnect.de. [91.0.201.230]) + by mx.google.com with ESMTPSA id p5sm1684154lag.1.2014.10.10.02.44.47 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Fri, 10 Oct 2014 02:44:48 -0700 (PDT) +Date: Fri, 10 Oct 2014 11:44:57 +0200 +Message-ID: <20141010114457.GG28601@TP_L520.localdomain> +From: Franz Fellner +To: notmuch@notmuchmail.org +Subject: Re: [PATCH] VIM: Add URI handling +In-Reply-To: <1412281423-22441-1-git-send-email-imain@stemwinder.org> +References: <1412281423-22441-1-git-send-email-imain@stemwinder.org> +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Fri, 10 Oct 2014 09:44:58 -0000 + +Works nice. Tested with an https and a mailto URI. +But it would be awesome if you could add message id handling, So one +could easily navigate to linked messages. I only found emacs client +implement this feature. What I read in the docs about ruby URI module +it should be fairly easy to add a custom scheme for id. + +On Thu, 2 Oct 2014 13:23:43 -0700, Ian Main wrote: +> This patch adds URI handling to the vim client. You can now press +> 'u' by default and the client will parse the current line and find +> any URIs available. If there are more than one it opens the one +> under the cursor or else it opens the only one available. It also +> supports mailto: URI's and will compose a new message when activated. +> +> By default xdg-open is used for everything but mailto: which generally +> does the right thing afaict. +> +> Ian +> --- +> vim/notmuch.txt | 1 + +> vim/notmuch.vim | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++------- +> 2 files changed, 53 insertions(+), 7 deletions(-) +> +> diff --git a/vim/notmuch.txt b/vim/notmuch.txt +> index 4374102..d336406 100644 +> --- a/vim/notmuch.txt +> +++ b/vim/notmuch.txt +> @@ -72,6 +72,7 @@ q Quit view +> A Archive (-inbox -unread) +> I Mark as read (-unread) +> t Tag (prompted) +> +u Open URI +> s Search +> p Save patches +> r Reply +> diff --git a/vim/notmuch.vim b/vim/notmuch.vim +> index 331e930..de82bb9 100644 +> --- a/vim/notmuch.vim +> +++ b/vim/notmuch.vim +> @@ -12,7 +12,7 @@ let g:notmuch_folders_maps = { +> \ '': 'folders_show_search()', +> \ 's': 'folders_search_prompt()', +> \ '=': 'folders_refresh()', +> - \ 'c': 'compose()', +> + \ 'c': 'compose("")', +> \ } +> +> let g:notmuch_search_maps = { +> @@ -25,7 +25,7 @@ let g:notmuch_search_maps = { +> \ 's': 'search_search_prompt()', +> \ '=': 'search_refresh()', +> \ '?': 'search_info()', +> - \ 'c': 'compose()', +> + \ 'c': 'compose("")', +> \ } +> +> let g:notmuch_show_maps = { +> @@ -37,10 +37,11 @@ let g:notmuch_show_maps = { +> \ 'e': 'show_extract_msg()', +> \ 's': 'show_save_msg()', +> \ 'p': 'show_save_patches()', +> + \ 'u': 'show_open_uri()', +> \ 'r': 'show_reply()', +> \ '?': 'show_info()', +> \ '': 'show_next_msg()', +> - \ 'c': 'compose()', +> + \ 'c': 'compose("")', +> \ } +> +> let g:notmuch_compose_maps = { +> @@ -59,6 +60,7 @@ let s:notmuch_datetime_format_default = '%d.%m.%y %H:%M:%S' +> let s:notmuch_reader_default = 'mutt -f %s' +> let s:notmuch_sendmail_default = 'sendmail' +> let s:notmuch_folders_count_threads_default = 0 +> +let s:notmuch_open_uri_default = 'xdg-open' +> +> function! s:new_file_buffer(type, fname) +> exec printf('edit %s', a:fname) +> @@ -135,8 +137,8 @@ function! s:show_reply() +> startinsert! +> endfunction +> +> -function! s:compose() +> - ruby open_compose +> +function! s:compose(to_email) +> + ruby open_compose(VIM::evaluate('a:to_email')) +> let b:compose_done = 0 +> call s:set_map(g:notmuch_compose_maps) +> autocmd BufDelete call s:on_compose_delete() +> @@ -159,6 +161,45 @@ ruby << EOF +> EOF +> endfunction +> +> +function! s:show_open_uri() +> + let line = getline(".") +> + let pos = getpos(".") +> + let col = pos[2] +> +ruby << EOF +> + m = get_message +> + line = VIM::evaluate('line') +> + col = VIM::evaluate('col') - 1 +> + uris = URI.extract(line) +> + wanted_uri = nil +> + if uris.length == 1 +> + wanted_uri = uris[0] +> + else +> + uris.each do |uri| +> + # Check to see the URI is at the present cursor location +> + idx = line.index(uri) +> + if col >= idx and col <= idx + uri.length +> + wanted_uri = uri +> + break +> + end +> + end +> + end +> + +> + if wanted_uri +> + uri = URI.parse(wanted_uri) +> + if uri.class == URI::MailTo +> + vim_puts("Composing new email to #{uri.to}.") +> + VIM::command("call s:compose('#{uri.to}')") +> + else +> + vim_puts("Opening #{uri.to_s}.") +> + cmd = VIM::evaluate('g:notmuch_open_uri') +> + system(cmd, uri.to_s) +> + end +> + else +> + vim_puts('URI not found.') +> + end +> +EOF +> +endfunction +> + +> function! s:show_open_msg() +> ruby << EOF +> m = get_message +> @@ -404,6 +445,10 @@ function! s:set_defaults() +> endif +> endif +> +> + if !exists('g:notmuch_open_uri') +> + let g:notmuch_open_uri = s:notmuch_open_uri_default +> + endif +> + +> if !exists('g:notmuch_reader') +> if exists('g:notmuch_rb_reader') +> let g:notmuch_reader = g:notmuch_rb_reader +> @@ -611,11 +656,11 @@ ruby << EOF +> open_compose_helper(lines, cur) +> end +> +> - def open_compose() +> + def open_compose(to_email) +> lines = [] +> +> lines << "From: #{$email}" +> - lines << "To: " +> + lines << "To: #{to_email}" +> cur = lines.count +> +> lines << "Cc: " +> -- +> 1.9.3 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch