🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nn
1 messages
1 total messages Started by Bryan O'Sullivan Tue, 15 Feb 1994 01:21
nn-mode.el v0.1 (use Emacs to edit within the NN newsreader)
#5447
Author: Bryan O'Sullivan
Date: Tue, 15 Feb 1994 01:21
170 lines
6749 bytes
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.

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.1
;; Date: 94-02-15 00:46

;; 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 (make sure
;; the server is running!), and 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-9]+$" . nn-mode))
;;				       auto-mode-alist))
;; Make sure the value of `nn-included-mark' is set to correspond to
;; the value of `included-mark' in your ~/.nn/init.

;; 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.

(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)

  (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 "In article <\\([^>]+\\)>, \\(.*\\) writes:")
	       (setq start (match-beginning 2)
		     end (match-beginning 2)))
	      ((looking-at "\\(.*\\) writes:")
	       (setq start (match-beginning 1)
		     end (match-beginning 1)))))

    ;; 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.
-- 
Bryan O'Sullivan
Department of Computer Science
Trinity College Dublin
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads