🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nn
Article #5468

nn-mode v0.3 -- edit replies and followups using Emacs

#5468
From: Bryan O'Sullivan
Date: Fri, 18 Feb 1994 00:35
212 lines
7940 bytes
Here follows the new, less buggy nn-mode.  I have been using Kim
Storm's NN newsreader for several years now, and over the last year or
so, I have also become a devotee of Emacs.  As I was rather disgusted
with the sloth of GNUS, I wrote the following mode to make editing of
NN articles from within Emacs easier.
 
This mode is aimed specifically at people who use a package such as
Supercite as part of their mail setup within Emacs, and would like to
be able to use it for following up and replying to news articles from
NN too.  I've tested it with Emacs 19.22 and NN 6.4.16 without any
problems; nn-mode will take some hackery at least to get running under
emacs 18, however.
 
You'll still have to run NN from your terminal (unless someone has a
VT-100 emulation package for Emacs that they would care to post!), so
unless you have a terminal that is capable of running multiple
sessions (i.e. an X terminal or something), jumping between Emacs and
NN might be a little awkward.

See the commentary for further details.  Bug reports are welcome.

	<b
--------cut here--------
;;; nn-mode.el --- major mode for editing NN mail and post buffers

;; Copyright (C) 1994 Bryan O'Sullivan

;; Author: Bryan O'Sullivan <bosullvn@maths.tcd.ie>
;; Keywords: news, server, processes
;; Version: 0.3
;; Date: 94-02-18 00:24

;; 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 1, 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, write to the Free Software
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

;; COMMENTARY:

;; This mode is intended for use by people who use Kim Storm's NN as
;; their newsreader, but prefer to use Emacs---along with packages
;; such as Supercite, which make use of `mail-citation-hook'---as
;; their editor.  It allows packages such as Supercite to `correctly'
;; (modulo any errors due to the hackiness of the work necessary)
;; transmogrify your buffer in the way you already know and love if
;; you are used to using such packages with VM, RMAIL, or (ugh!) GNUS.

;; You must use `emacsclient' as your editor from within NN.  This can
;; be done, if you use the Bourne shell or one of its derivatives, by
;; starting NN with the line `EDITOR=emacsclient nn', or by adding the
;; following line to your `~/.nn/init':

;;	set editor emacsclient

;; Also, make sure that the Emacs server is running, either by typing
;; `C-x #' within from within Emacs, or by adding the following line
;; to your `~/.emacs':

;;	(server-start)

;; You should also include something akin to the following piece of
;; elisp in your `~/.emacs':

;;	(autoload 'nn-mode "nn-mode" "Autoload NN mode." t)
;;	(setq auto-mode-alist (append '(("nn\\.[0-9a-z]+$" . nn-mode))
;;				       auto-mode-alist))

;; Make sure the value of `nn-included-mark' is set to correspond to
;; the value, in your `~/.nn/init', of `included-mark'.  The default
;; should be okay if you haven't done anything to change
;; `included-mark'.

;; If you use Supercite, then you will also probably want the
;; following somewhere in your `.emacs':

;;	(add-hook 'mail-citation-hook 'sc-cite-original)

;; This will cause the message you are replying or following-up to to
;; be quoted properly by Supercite.

;; HISTORY:

;; 0.1	94-02-15 00:46
;;	Initial release.

;; 0.2	94-02-15 18:17
;;	Some bugs pointed out by Tom Moore fixed.

;; 0.3	94-02-18 00:24
;;	Fixed to work properly if `mail-citation-hook' is unset.

(require 'server)

(defvar nn-mode-hooks nil
  "A function or list of functions to be run on entering NN mode.")

(defvar nn-included-mark "^>"
  "The string (in regexp form) used to quote included articles when NN
does a followup or reply.")

(defvar nn-kill-saved-buffers t
  "Kill an NN buffer after saving it.  This is useful, as buffers
keep having to be manually reverted if they are kept around during
a newsreading session.")

(defun nn-mode ()
  "Major mode for editing NN mail and post buffers using the emacs
server.  The idea is that this function allows `mail-citation-hook'
to be called on a followup or reply buffer when the original message
is quoted.

Commands:
key		binding
---		-------
C-c C-s		nn-save-buffer

Entry to this mode calls the value of `nn-mode-hooks' if that
value is non-nil."
  (interactive)
  (kill-all-local-variables)
  (run-hooks 'nn-mode-hooks)
  (text-mode)
  (setq major-mode 'nn-mode
	mode-name (concat mode-name " NN"))
  (use-local-map nn-mode-map)

  (if mail-citation-hook
      (progn
	(undo-boundary)
  
	;; Set up the buffer for editing by stripping off the original
	;; NN attribution characters.
	(let ((buffer-top (point-min)))
	  (goto-char buffer-top)
	  (while (re-search-forward nn-included-mark nil t)
	    (replace-match "" nil nil))
	  (goto-char buffer-top))

	;; Find the sender of the original article to quote from.
	(let ((start nil)
	      (end nil))
	  ;; If this is a mail reply, find the originator.
	  (if (re-search-forward "^Orig-To: \\(.*\\)$" (point-max) t)
	      (setq start (match-beginning 1)
		    end (match-end 1)))
	  (re-search-forward "^$")
	  (forward-line 1)

	  ;; If this is not a mail reply (i.e. we're following up to
	  ;; another article), find the original author in one of the
	  ;; two standard NN attribution styles.
	  (if (not start)
	      (cond ((looking-at "\\(.*\\) writes:")
		     (setq start (match-beginning 1)
			   end (match-end 1)))
		    ((or (looking-at
			  "In <\\([^>]+\\)> \\(.*\\) writes:")
			 (looking-at
			  "In article <\\([^>]+\\)>, \\(.*\\) writes:"))
		     (setq start (match-beginning 2)
			   end (match-end 2)))))

	  ;; If we have found someone to cite, then set things up to
	  ;; have `mail-citation-hook' called properly according to
	  ;; the conventions described in the Supercite documentation.
	  ;; We have to fake a `From:' line.
	  (if start
	      (progn
		(forward-line 1)
		(insert "\n")
		(set-mark (point))
		(insert "From: " (buffer-substring start end) "\n")
		(goto-char (point-max))
		(run-hooks 'mail-citation-hook)))))))

(defun nn-save-buffer ()
  "Save a buffer, possibly killing it, and resume the newsreader."
  (interactive)
  (save-buffer)
  (let ((victim (buffer-name)))
    (server-edit)
    (if nn-kill-saved-buffers
	(kill-buffer victim))))

(defvar nn-mode-map nil
  "Keymap for NN major mode.")

(if nn-mode-map
    nil
  (setq nn-mode-map (make-sparse-keymap))
  (define-key nn-mode-map "\C-c\C-s" 'nn-save-buffer))

(provide 'nn-mode)
-------- cut here --------

The end.

	<b
-- 
Bryan O'Sullivan
Department of Computer Science
Trinity College Dublin
Technical Details
Message-ID: <2k12fo$ipe@walton.maths.tcd.ie>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-gnu.emacs.sources.mbox.zip!gmd.de!newsserver.jvnc.net!darwin.sura.net!howland.reston.ans.net!EU.net!ieunet!maths.tcd.ie!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <2k12fo$ipe@walton.maths.tcd.ie>
Subject: nn-mode v0.3 -- edit replies and followups using Emacs
Date: Fri, 18 Feb 1994 00:35:03 +0000
From: bosullvn@maths.tcd.ie (Bryan O'Sullivan)
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-gnu.emacs.sources.mbox.zip!gmd.de!newsserver.jvnc.net!darwin.sura.net!howland.reston.ans.net!EU.net!ieunet!maths.tcd.ie!not-for-mail
Newsgroups: news.software.nn,gnu.emacs.sources
Organization: University of Dublin, Trinity College
Lines: 211
NNTP-Posting-Host: walton.maths.tcd.ie
Keywords: NN, Emacs