Tag: Lisp

Integrate mu4e with gnus

I have used mu4e for email searching too. Based on the code in this post, I found it is quite easy to integrate mu4e with gnus too. The following code is for that, the mu4e version is 0.918, Emacs version is 25.3.

Same as code to integrate notmuch with gnus, there’s no general implementation of hy-notmuch-file-to-group, so you need to revise it for your own configuration.

(require 'mu4e)
(require 'org-gnus)

(defun hy-mu4e-maildir-to-group (maildir)
  "Calculate the Gnus group name from the given maildir.

Example:
  IN: /outlook/Inbox
  OUT: nnmaildir+outlook:Inbox
"
  (replace-regexp-in-string "^/\\([^/]+\\)/\\([^/]+\\)"
                            "nnmaildir+\\1:\\2"
                            maildir t))

(defun hy-mu4e-goto-message-in-gnus ()
  "Open a summary buffer containing the current mu4e article."
  (interactive)
  (let ((group (hy-mu4e-maildir-to-group
                (mu4e-message-field-at-point :maildir)))
        (message-id (mu4e-message-field-at-point :message-id)))
    (if (and group message-id)
        (org-gnus-follow-link group message-id)
      (message "Couldn't get relevant infos for switching to Gnus."))))

(define-key mu4e-headers-mode-map (kbd "C-c C-c")
  'hy-mu4e-goto-message-in-gnus)

(define-key mu4e-view-mode-map (kbd "C-c C-c")
  'hy-mu4e-goto-message-in-gnus)
Advertisements

Integrate notmuch with gnus

I have usaed gnus as my main email client for years. I am happy with it in general. But there’s at least one problem, searching performance isn’t good. And I have tens thousands emails accumulated in past 10 years and subscribed several mailing list. Via googling, I found a way to integrate notmuch with gnus as in this post. But the post is written in 2009, so I made some changes to make it work in Emacs25 and latest notmuch (0.25.2).

There’s no general implementation of hy-notmuch-file-to-group, so you need to revise it for your own configuration.

(require 'notmuch)
(require 'org-gnus)

(defun hy-notmuch-file-to-group (file)
  "Calculate the Gnus group name from the given file name.

Example:

  IN:
/home/caritas/OfflineMail/outlook/Inbox/cur/1511528325_2.19059.yhuang6-yoga3pro,U=63,FMD5=3882d32c66e7e768145ecd8f104b0c08:2,S

  OUT: nnmaildir+outlook:Inbox
"
  (let ((group (file-name-directory (directory-file-name
                                     (file-name-directory file)))))
    (setq group (replace-regexp-in-string "/home/caritas/OfflineMail/" ""
                                          group))
    (setq group (replace-regexp-in-string "^\\([^/]+\\)/" "nnmaildir+\\1:"
                                          group t))
    (setq group (replace-regexp-in-string "/$" "" group))
    (if (string-match ":$" group)
        (concat group "INBOX")
      (replace-regexp-in-string ":\\." ":" group))))

(defun hy-notmuch-goto-message-in-gnus ()
  "Open a summary buffer containing the current notmuch
article."
  (interactive)
  (let ((group (hy-notmuch-file-to-group (notmuch-show-get-filename)))
        (message-id (notmuch-show-get-message-id t)))
    (if (and group message-id)
        (org-gnus-follow-link group message-id)
      (message "Couldn't get relevant infos for switching to Gnus."))))

(define-key notmuch-show-mode-map (kbd "C-c C-c")
  'hy-notmuch-goto-message-in-gnus)

Comint Intercept: Combine shell/eshell/term mode

This is another Emacs package I developed recently to make my life better.

https://github.com/hying-caritas/comint-intercept

Comint Intercept

Why

Intercept the input in comint-mode. This can be used to run eshell command, or run some command in a terminal buffer from the command line in shell buffer. That is, this is to combine the best part of shell, eshell and term mode. For example, you can run eshell `grep’ in the shell buffer, or when you run `top’ in the shell buffer, a terminal buffer is poped to run it. SSH is supported to run command remotely.

Install

The preferred install method is through package manager: package.el. comint-intercept is available in MELPA package repository.

Or you can download the comint-intercept.el, add its path into Emacs load path, and load the file. For example, add

(add-to-list 'load-path "<directory of comint-intercept.el>")
(require 'comint-intercept)

in your Emacs init file.

Usage

A minor mode named comint-intercept-mode is defined. To toggle it in a shell buffer or some other comint mode buffer, you can run command comint-intercept-mode. Or you can enable comint-intercept-mode automatically when you create a new shell mode buffer via,

(add-hook 'shell-mode-hook 'comint-intercept-mode)

Then you can run eshell command via

$ e <eshell command>

Or run some eshell command directly via customizing comint-intercept-eshell-commands.

To run command in term mode, you can use

$ t <command> <args>...

Or run commands in term mode directly via customizing comint-intercept-term-commands.

If you want something more general, you can customize comint-intercept-pattern-actions, which is an alist maps input pattern (regexp) to action to take (function). The input string will be fed to the action function. Then you can process the input string via eshell-command or comint-intercept-term-command provided by the package.