From 7c2749ecb244e70385bd3aabfc5e99bbcbd4a1b0 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Sun, 3 Jan 2016 23:06:52 +0100 Subject: [PATCH] Re: [PATCH v4] devel/emacs: add devel/try-emacs-mua --- 34/4f5c6cc8a86ebe19c2702432c148d59d26d635 | 278 ++++++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 34/4f5c6cc8a86ebe19c2702432c148d59d26d635 diff --git a/34/4f5c6cc8a86ebe19c2702432c148d59d26d635 b/34/4f5c6cc8a86ebe19c2702432c148d59d26d635 new file mode 100644 index 000000000..797d2f368 --- /dev/null +++ b/34/4f5c6cc8a86ebe19c2702432c148d59d26d635 @@ -0,0 +1,278 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 931DA6DE177E + for ; Sun, 3 Jan 2016 14:13:13 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -1.475 +X-Spam-Level: +X-Spam-Status: No, score=-1.475 tagged_above=-999 required=5 tests=[AWL=0.805, + RCVD_IN_DNSWL_MED=-2.3, T_FRT_BELOW2=0.01, + T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id UlX7We7heU3T for ; + Sun, 3 Jan 2016 14:13:09 -0800 (PST) +X-Greylist: delayed 370 seconds by postgrey-1.35 at arlo; + Sun, 03 Jan 2016 14:13:09 PST +Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36]) + by arlo.cworth.org (Postfix) with ESMTP id A64A46DE1769 + for ; Sun, 3 Jan 2016 14:13:09 -0800 (PST) +Received: from localhost (unknown [192.168.200.7]) + by max.feld.cvut.cz (Postfix) with ESMTP id 209D319F49A7; + Sun, 3 Jan 2016 23:06:56 +0100 (CET) +X-Virus-Scanned: IMAP STYX AMAVIS +Received: from max.feld.cvut.cz ([192.168.200.1]) + by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new, port 10044) + with ESMTP id ba4F7ygdfeRn; Sun, 3 Jan 2016 23:06:53 +0100 (CET) +Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34]) + by max.feld.cvut.cz (Postfix) with ESMTP id C2F7B19F46FB; + Sun, 3 Jan 2016 23:06:53 +0100 (CET) +Received: from wsh by steelpick.2x.cz with local (Exim 4.86) + (envelope-from ) + id 1aFqnc-0006lY-SA; Sun, 03 Jan 2016 23:06:52 +0100 +From: Michal Sojka +To: Tomi Ollila , notmuch@notmuchmail.org +Subject: Re: [PATCH v4] devel/emacs: add devel/try-emacs-mua +In-Reply-To: <1450610032-23776-1-git-send-email-tomi.ollila@iki.fi> +References: <1450610032-23776-1-git-send-email-tomi.ollila@iki.fi> +User-Agent: Notmuch/0.21+30~g55c056a (http://notmuchmail.org) Emacs/24.5.1 + (x86_64-pc-linux-gnu) +Date: Sun, 03 Jan 2016 23:06:52 +0100 +Message-ID: <87vb7aco77.fsf@steelpick.2x.cz> +MIME-Version: 1.0 +Content-Type: text/plain +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +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: Sun, 03 Jan 2016 22:13:13 -0000 + +Hi Tomi, + +On Sun, Dec 20 2015, Tomi Ollila wrote: +> devel/try-emacs-mua provides an easy way to try and experiment +> with the notmuch emacs client distributed in emacs subdirectory of +> the notmuch source tree. +> +> try-emacs-mua starts a new emacs process and if initial checks pass +> *scratch* buffer is filled with information of how to begin. +> +> User can add normal emacs flags, like -q, -Q and e.g. -f notmuch. Any +> given plain filename arguments are filtered out (with message). + +Why are plain files filtered? Yesterday, when I experimented with +jl-encrypt.el, I started emacs like: + + emacs -Q --directory ... --load notmuch.el /tmp/jl-encrypt.el + +This allowed me to experiment with it (edebug), modify it and restart +emacs sessions easily without the need to type C-x C-f and the file name +in every session. + +> If the emacs version in use is smaller than 24.4, special care is taken +> to ensure that notmuch*.elc files older than corresponding .el files +> are not loaded. Since emacs 24.4, setting `load-prefer-newer' variable +> takes care of this. +> --- +> +> Now all-elisp, vs v3: id:1447457397-11688-1-git-send-email-tomi.ollila@iki.fi +> +> In id:87si4bwrsu.fsf@qmul.ac.uk Mark had some thoughts if something from this +> could perhaps be used as some idea how to improve test testing. We'll have +> to think more of that later. Rest of the review is pretty much irrelevant +> for this (But I fixed that particular bug before turning to this ;). +> +> devel/try-emacs-mua | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++ +> 1 file changed, 153 insertions(+) +> create mode 100755 devel/try-emacs-mua +> +> diff --git a/devel/try-emacs-mua b/devel/try-emacs-mua +> new file mode 100755 +> index 000000000000..1f916d2806f9 +> --- /dev/null +> +++ b/devel/try-emacs-mua +> @@ -0,0 +1,153 @@ +> +#!/bin/sh +> +:; set -x; exec "${EMACS:-emacs}" --debug-init --load "$0" "$@"; exit + +Huh! Nice trick, especially the ":;" :) + +> +;; +> +;; Try the notmuch emacs client located in ../notmuch/emacs directory +> +;; +> +;; Run this without arguments; emacs window opens with some usage information +> +;; +> +;; Authors: Tomi Ollila +> +;; +> +;; http://www.emacswiki.org/emacs/EmacsScripts was a useful starting point... +> +;; +> +;; Licence: GPLv3+ +> +;; +> + +> +(message "Starting '%s'" load-file-name) +> + +> +(set-buffer "*scratch*") +> + +> +(setq initial-buffer-choice t) ;; *scratch* buffer +> + +> +(when (featurep 'notmuch) +> + (insert " +> +Notmuch has been loaded to this emacs (during processing of the init file) +> +which means it is (most probably) loaded from different source than expected. +> + +> +Please run \"" (file-name-nondirectory load-file-name) +> +"\" with '-q' (or '-Q') as an argument, to disable +> +processing of the init file -- you can load it after emacs has started\n +> +exit emacs (y or n)? ") +> + (if (y-or-n-p "exit emacs") +> + (kill-emacs) +> + (error "Stopped reading %s" load-file-name))) +> + +> +(let ((pdir (file-name-directory +> + (directory-file-name (file-name-directory load-file-name))))) +> + (unless (file-exists-p (concat pdir "emacs/notmuch-lib.el")) +> + (insert "Cannot find notmuch-emacs source directory +> +while looking at: " pdir "emacs\n\nexit emacs (y or n)? ") +> + (if (y-or-n-p "exit emacs") +> + (kill-emacs) +> + (error "Stopped reading %s" load-file-name))) +> + (setq try-notmuch-source-directory (directory-file-name pdir)) +> + (setq try-notmuch-emacs-directory (concat pdir "emacs/")) +> + (setq load-path (cons try-notmuch-emacs-directory load-path))) +> + +> +;; for logging, debugging and load tracing (broke on emacs 24.5.1 :O) +> +;;(defadvice file-truename (before before-file-truename activate) +> +;;;; (message "file-truename: '%s' '%s' '%s'" filename counter prev-dirs)) +> +;; (unless counter +> +;; (message "file-truename: %s" filename))) + +What is the benefit of advising file-truename? Especially when you do +other type of logging below. I'd prefer to have this as a comment in the +file. Or is this some leftover from your experiments? + +> + +> +;; they say advice doesn't work for primitives (functions from c source) +> +;; well, these 'before' advice works for emacs 23.1 - 24.5 (at least) +> +;; ...and for our purposes 24.3 is enough (there is no load-prefer-newer there) +> +;; note also that the old, "obsolete" defadvice mechanism was used, but that +> +;; is the only one available for emacs 23 and 24 up to 24.3. +> + +> +(if (boundp 'load-prefer-newer) +> + (defadvice require (before before-require activate) +> + (unless (featurep feature) +> + (message "require: %s" feature))) +> + ;; else: special require "short-circuit"; after load feature is provided... +> + ;; ... in notmuch sources we always use require and there are no loops +> + (defadvice require (before before-require activate) +> + (unless (featurep feature) +> + (message "require: %s" feature) +> + (let ((name (symbol-name feature))) +> + (if (and (string-match "^notmuch" name) +> + (file-newer-than-file-p +> + (concat try-notmuch-emacs-directory name ".el") +> + (concat try-notmuch-emacs-directory name ".elc"))) +> + (load (concat try-notmuch-emacs-directory name ".el") nil nil t t) +> + ))))) +> + +> +(insert "Found notmuch emacs client in " try-notmuch-emacs-directory "\n") +> + +> +(condition-case err +> +;; "opportunistic" load-prefer-newer -- will be effective since emacs 24.4 +> + (let ((load-prefer-newer t) +> + (force-load-messages t)) +> + (require 'notmuch)) +> + ;; specifying `debug' here lets the debugger run +> + ;; if `debug-on-error' is non-nil. +> + ((debug error) +> + (progn +> + (insert "\nLoading notmuch failed: " (error-message-string err) "\n") +> + (insert "See *Messages* buffer for more information.\n") +> + (error "Stopped reading %s" load-file-name)))) +> + +> +(insert " +> +Go to the end of the following lines and type C-x C-e to evaluate +> +(or C-j which is shorter but inserts evaluation results into buffer) +> + +> +To \"disable\" mail sending, evaluate +> +* (setq message-send-mail-function (lambda () t)) +> +") +> + +> +(if (file-exists-p (concat try-notmuch-source-directory "/notmuch")) +> + (insert " +> +To use accompanied notmuch binary from the same source, evaluate +> +* (setq exec-path (cons \"" try-notmuch-source-directory "\" exec-path)) +> +Note: Evaluating the above may be followed by unintended database +> +upgrade and getting back to old version may require dump & restore. +> +")) + +You can also inform the user which notmuch binary will be used without +the above setq. + +> + +> +(if init-file-user ;; nil, if '-q' or '-Q' is given, but no '-u' 'USER' +> + (insert " +> +Your init file was processed during emacs startup. If you want to test +> +notmuch emacs mail client without your emacs init file interfering, Run\n\"" +> +(file-name-nondirectory load-file-name) "\" with '-q' (or '-Q') as an argument. +> +") +> + (let ((init-file-name)) +> + ;; determining init file name in startup.el/command-line is too complicated +> + ;; to be duplicated here; these 3 file names covers most of the users +> + (mapc (lambda (fn) (if (file-exists-p fn) (setq init-file-name fn))) +> + '("~/.emacs.d/init.el" "~/.emacs" "~/.emacs.el")) +> + (if init-file-name +> + (insert " +> +If you want to load your emacs init file now, evaluate +> +* (load \"" init-file-name "\") +> +"))) +> + (insert " +> +If you want to use packages (e.g. company from elpa) evaluate +> +* (progn (require 'package) (package-initialize)) +> +")) +> + +> +(insert " +> +To start notmuch (hello) screen, evaluate +> +* (notmuch-hello)") +> + +> +(setq try-emacs-pop-messages-buffers nil) + +If this variable was named something like arg-ignored, the code bellow +would be easier to understand. + +> +(add-hook 'command-line-functions +> + (lambda () +> + (unless try-emacs-pop-messages-buffers (message "%s" "")) +> + (message "*** Ignoring arg '%s'" argi) +> + (setq try-emacs-pop-messages-buffers t))) +> + +> +(add-hook 'emacs-startup-hook +> + (lambda () +> + (when try-emacs-pop-messages-buffers +> + (message "%s" "") +> + (message "Press 'q' to hide this window") + +Pressing 'q' doesn't work under Emacs 23. + +> + (pop-to-buffer "*Messages*")) +> + (set-buffer "*scratch*") +> + (lisp-interaction-mode) +> + (goto-char (point-min)) +> + (forward-line) +> + (set-buffer-modified-p nil))) +> + +> +;; Local Variables: +> +;; mode: emacs-lisp +> +;; End: + +-Michal -- 2.26.2