From: David Bremner Date: Sat, 3 Jan 2015 12:58:20 +0000 (+0100) Subject: [PATCH 2/2] completion: generate notmuch-completion.zsh using doc/conf.py X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1b3f144c6898bc6dd3315e86955aadb836268f40;p=notmuch-archives.git [PATCH 2/2] completion: generate notmuch-completion.zsh using doc/conf.py --- diff --git a/d4/f65416ce94ae8f946e4f18a2b56856e3b541eb b/d4/f65416ce94ae8f946e4f18a2b56856e3b541eb new file mode 100644 index 000000000..72ca959fb --- /dev/null +++ b/d4/f65416ce94ae8f946e4f18a2b56856e3b541eb @@ -0,0 +1,310 @@ +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 D99A5431FC0 + for ; Sat, 3 Jan 2015 04:59:03 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + 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 ntckZBX7tsXi for ; + Sat, 3 Jan 2015 04:59:01 -0800 (PST) +Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155]) + (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 2F9FC431FDB + for ; Sat, 3 Jan 2015 04:59:01 -0800 (PST) +Received: from remotemail by yantan.tethera.net with local (Exim 4.80) + (envelope-from ) + id 1Y7OIG-0006EZ-6l; Sat, 03 Jan 2015 08:59:00 -0400 +Received: (nullmailer pid 29794 invoked by uid 1000); Sat, 03 Jan 2015 + 12:58:54 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [PATCH 2/2] completion: generate notmuch-completion.zsh using + doc/conf.py +Date: Sat, 3 Jan 2015 13:58:20 +0100 +Message-Id: <1420289900-29717-2-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.3 +In-Reply-To: <1420289900-29717-1-git-send-email-david@tethera.net> +References: <1420289900-29717-1-git-send-email-david@tethera.net> +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +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: Sat, 03 Jan 2015 12:59:04 -0000 + +I noticed that the (out of date) list of subcommands was simply +repeating the summary lines from the manpage. Since those summary +lines are already kept in machine readable form in doc/conf.py, +it's easy to compute that part of the completion file. +--- + completion/Makefile.local | 12 ++++- + completion/gen-zsh-completion.py | 108 ++++++++++++++++++++++++++++++++++++++ + completion/notmuch-completion.zsh | 96 --------------------------------- + 3 files changed, 119 insertions(+), 97 deletions(-) + create mode 100644 completion/gen-zsh-completion.py + delete mode 100644 completion/notmuch-completion.zsh + +diff --git a/completion/Makefile.local b/completion/Makefile.local +index dfc1271..616afa4 100644 +--- a/completion/Makefile.local ++++ b/completion/Makefile.local +@@ -6,7 +6,15 @@ dir := completion + # directly in any shell commands. Instead we save its value in other, + # private variables that we can use in the commands. + bash_script := $(srcdir)/$(dir)/notmuch-completion.bash +-zsh_script := $(srcdir)/$(dir)/notmuch-completion.zsh ++gen_zsh_script := $(srcdir)/$(dir)/gen-zsh-completion.py ++conf_file := $(srcdir)/$(dir)/../doc/conf.py ++ ++$(dir)/notmuch-completion.zsh: $(dir)/gen-zsh-completion.py ++ $(PYTHON) $(gen_zsh_script) $(conf_file) > $@ ++ ++ifeq ($(WITH_ZSH),1) ++all: $(dir)/notmuch-completion.zsh ++endif + + install: install-$(dir) + +@@ -20,3 +28,5 @@ ifeq ($(WITH_ZSH),1) + mkdir -p "$(DESTDIR)$(zsh_completion_dir)" + install -m0644 $(zsh_script) "$(DESTDIR)$(zsh_completion_dir)/_notmuch" + endif ++ ++CLEAN += $(dir)/notmuch-completion.zsh +diff --git a/completion/gen-zsh-completion.py b/completion/gen-zsh-completion.py +new file mode 100644 +index 0000000..26cd13e +--- /dev/null ++++ b/completion/gen-zsh-completion.py +@@ -0,0 +1,108 @@ ++# Copyright 2014 David Bremner ++# ++# This program is free software: you can redistribute it and/or modify ++# it under the terms of the GNU General Public License as published by ++# the Free Software Foundation, either version 3 of the License, or ++# (at your option) any later version. ++# ++# This program is distributed in the hope that it will be useful, ++# but WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++# GNU General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with this program. If not, see http://www.gnu.org/licenses/ . ++# ++# This script is based on notmuch-completion.zsh, by ++# Ingmar Vanhassel ++ ++from sys import argv ++ ++conffile = argv[1] ++ ++with open(conffile) as cf: ++ exec(cf.read()) ++ ++print(r'''#compdef notmuch ++ ++# This file was generated from gen-zsh-completion.py in the notmuch source. ++# You should probably not edit it directly ++_notmuch_commands() ++{ ++ local -a notmuch_commands ++ notmuch_commands=( ++ 'help:display documentation for a subcommand' ++ 'setup:interactively configure notmuch' ++''') ++ ++for command in man_pages: ++ parts=command[1].split('-') ++ if len(parts) == 1 or command[4] != 1: ++ continue ++ print (' \'{0:s}:{1:s}\''.format(parts[1],command[2])) ++ ++print ( ++r''' ) ++ ++ _describe -t command 'command' notmuch_commands ++} ++ ++_notmuch_dump() ++{ ++ _files ++} ++ ++_notmuch_help_topics() ++{ ++ local -a notmuch_help_topics ++ notmuch_help_topics=( ++ 'search-terms:show common search-terms syntax' ++ ) ++ _describe -t notmuch-help-topics 'topic' notmuch_help_topics ++} ++ ++_notmuch_help() ++{ ++ _alternative \ ++ _notmuch_commands \ ++ _notmuch_help_topics ++} ++ ++_notmuch_restore() ++{ ++ _files ++} ++ ++_notmuch_search() ++{ ++ _arguments -s : \ ++ '--max-threads=[display only the first x threads from the search results]:number of threads to show: ' \ ++ '--first=[omit the first x threads from the search results]:number of threads to omit: ' \ ++ '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \ ++ '--output=[select what to output]:output:((summary threads messages files tags))' ++} ++ ++_notmuch_address() ++{ ++ _arguments -s : \ ++ '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \ ++ '--output=[select what to output]:output:((sender recipients count))' ++} ++ ++_notmuch() ++{ ++ if (( CURRENT > 2 )) ; then ++ local cmd=${words[2]} ++ curcontext="${curcontext%:*:*}:notmuch-$cmd" ++ (( CURRENT-- )) ++ shift words ++ _call_function ret _notmuch_$cmd ++ return ret ++ else ++ _notmuch_commands ++ fi ++} ++ ++_notmuch "$@" ++ ++''') +diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-completion.zsh +deleted file mode 100644 +index 46b33d1..0000000 +--- a/completion/notmuch-completion.zsh ++++ /dev/null +@@ -1,96 +0,0 @@ +-#compdef notmuch +- +-# ZSH completion for `notmuch` +-# Copyright © 2009 Ingmar Vanhassel +-# +-# This program is free software: you can redistribute it and/or modify +-# it under the terms of the GNU General Public License as published by +-# the Free Software Foundation, either version 3 of the License, or +-# (at your option) any later version. +-# +-# This program is distributed in the hope that it will be useful, +-# but WITHOUT ANY WARRANTY; without even the implied warranty of +-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-# GNU General Public License for more details. +-# +-# You should have received a copy of the GNU General Public License +-# along with this program. If not, see http://www.gnu.org/licenses/ . +- +-_notmuch_commands() +-{ +- local -a notmuch_commands +- notmuch_commands=( +- 'setup:interactively set up notmuch for first use' +- 'new:find and import any new message to the database' +- 'search:search for messages matching the search terms, display matching threads as results' +- 'address:get addresses from messages matching the given search terms' +- 'reply:constructs a reply template for a set of messages' +- 'show:show all messages matching the search terms' +- 'tag:add or remove tags for all messages matching the search terms' +- 'dump:creates a plain-text dump of the tags of each message' +- 'restore:restores the tags from the given file' +- 'help:show details on a command' +- ) +- +- _describe -t command 'command' notmuch_commands +-} +- +-_notmuch_dump() +-{ +- _files +-} +- +-_notmuch_help_topics() +-{ +- local -a notmuch_help_topics +- notmuch_help_topics=( +- 'search-terms:show common search-terms syntax' +- ) +- _describe -t notmuch-help-topics 'topic' notmuch_help_topics +-} +- +-_notmuch_help() +-{ +- _alternative \ +- _notmuch_commands \ +- _notmuch_help_topics +-} +- +-_notmuch_restore() +-{ +- _files +-} +- +-_notmuch_search() +-{ +- _arguments -s : \ +- '--max-threads=[display only the first x threads from the search results]:number of threads to show: ' \ +- '--first=[omit the first x threads from the search results]:number of threads to omit: ' \ +- '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \ +- '--output=[select what to output]:output:((summary threads messages files tags))' +-} +- +-_notmuch_address() +-{ +- _arguments -s : \ +- '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \ +- '--output=[select what to output]:output:((sender recipients count))' +-} +- +-_notmuch() +-{ +- if (( CURRENT > 2 )) ; then +- local cmd=${words[2]} +- curcontext="${curcontext%:*:*}:notmuch-$cmd" +- (( CURRENT-- )) +- shift words +- _call_function ret _notmuch_$cmd +- return ret +- else +- _notmuch_commands +- fi +-} +- +-_notmuch "$@" +- +-# vim: set sw=2 sts=2 ts=2 et ft=zsh : +-- +2.1.3 +