summaryrefslogtreecommitdiffhomepage
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/jao-ednc.el115
-rw-r--r--misc/jao-minibuffer.el104
-rw-r--r--misc/jao-random-album.el101
-rw-r--r--misc/randomsig.el724
4 files changed, 0 insertions, 1044 deletions
diff --git a/misc/jao-ednc.el b/misc/jao-ednc.el
deleted file mode 100644
index 48223d8..0000000
--- a/misc/jao-ednc.el
+++ /dev/null
@@ -1,115 +0,0 @@
-;;; jao-ednc.el --- Minibuffer notifications using EDNC -*- lexical-binding: t; -*-
-
-;; Copyright (C) 2020 jao
-
-;; Author: jao <mail@jao.io>
-;; Keywords: tools, abbrev
-
-;; 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 <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Use the ednc package to provide a notification daemon that uses
-;; the minibuffer to display them.
-
-;;; Code:
-
-(require 'ednc)
-(require 'jao-minibuffer)
-
-(declare-function tracking-add-buffer "tracking")
-(declare-function tracking-remove-buffer "tracking")
-
-(defvar jao-ednc--count-format "{%d}")
-(defvar jao-ednc--last-notification nil)
-
-(defface jao-ednc-tracking '((t :inherit warning))
- "Tracking notifications face"
- :group 'jao-ednc)
-
-(defun jao-ednc--format-last ()
- (when jao-ednc--last-notification
- (let ((s (ednc-format-notification jao-ednc--last-notification t)))
- (replace-regexp-in-string "\n" " " s))))
-
-(defun jao-ednc--count ()
- (let ((no (length (ednc-notifications))))
- (if (> no 0) (format jao-ednc--count-format no) "")))
-
-(defvar jao-ednc--handlers ())
-
-(defun jao-ednc-add-handler (app handler)
- (add-to-list 'jao-ednc--handlers (cons app handler)))
-
-(defun jao-ednc--default-handler (notification newp)
- (if newp
- (progn
- (tracking-add-buffer (get-buffer ednc-log-name) '(jao-ednc-tracking))
- (setq jao-ednc--last-notification notification)
- (jao-minibuffer-push-notification '(:eval (jao-ednc--format-last))))
- (tracking-remove-buffer (get-buffer ednc-log-name))
- (setq jao-ednc--last-notification nil)
- (jao-minibuffer-pop-notification)))
-
-(defun jao-ednc--handler (notification)
- (alist-get (ednc-notification-app-name notification)
- jao-ednc--handlers
- #'jao-ednc--default-handler
- nil
- 'string=))
-
-(defun jao-ednc--on-notify (old new)
- (when old (funcall (jao-ednc--handler old) old nil))
- (when new (funcall (jao-ednc--handler new) new t)))
-
-;;;###autoload
-(defun jao-ednc-setup ()
- (setq jao-notify-use-messages-p t)
- (with-eval-after-load "tracking"
- (add-to-list 'tracking-faces-priorities 'jao-ednc-tracking)
- (when (listp tracking-shorten-modes)
- (add-to-list 'tracking-shorten-modes 'ednc-view-mode)))
- ;; (jao-minibuffer-add-variable '(jao-ednc--count) t)
- (add-hook 'ednc-notification-presentation-functions #'jao-ednc--on-notify)
- (ednc-mode))
-
-;;;###autoload
-(defun jao-ednc-pop ()
- (interactive)
- (pop-to-buffer-same-window ednc-log-name))
-
-;;;###autoload
-(defun jao-ednc-show ()
- (interactive)
- (if jao-ednc--last-notification
- (ednc-pop-to-notification-in-log-buffer jao-ednc--last-notification)
- (jao-ednc-pop)))
-
-;;;###autoload
-(defun jao-ednc-invoke-last-action ()
- (interactive)
- (if jao-ednc--last-notification
- (ednc-invoke-action jao-ednc--last-notification)
- (message "No active notifications"))
- (jao-minibuffer-pop-notification))
-
-;;;###autoload
-(defun jao-ednc-dismiss ()
- (interactive)
- (if jao-ednc--last-notification
- (ednc-dismiss-notification jao-ednc--last-notification)
- (jao-minibuffer-pop-notification)))
-
-(provide 'jao-ednc)
-;;; jao-ednc.el ends here
diff --git a/misc/jao-minibuffer.el b/misc/jao-minibuffer.el
deleted file mode 100644
index 7104544..0000000
--- a/misc/jao-minibuffer.el
+++ /dev/null
@@ -1,104 +0,0 @@
-;;; jao-minibuffer.el --- using the minibuffer to report status -*- lexical-binding: t; -*-
-
-;; Copyright (C) 2020 jao
-
-;; Author: jao <mail@jao.io>
-;; Keywords: extensions
-
-;; 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 <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Simple asynchronous display of information in the minibuffer.
-
-;;; Code:
-
-(defvar jao-minibuffer-info ())
-(defvar jao-minibuffer-notification nil)
-(defvar jao-minibuffer-align-right-p t)
-(defvar jao-minibuffer-right-margin (if window-system 0 1))
-(defvar jao-minibuffer-maximized-frames-p t)
-(defvar jao-minibuffer-notification-timeout 5)
-
-(defconst jao-minibuffer--name " *Minibuf-0*")
-
-(defun jao-minibuffer--trim (s w)
- (if (<= (length s) w)
- (format (format "%%%ds" w) s)
- (substring s 0 w)))
-
-(defun jao-minibuffer--current ()
- (with-current-buffer jao-minibuffer--name
- (buffer-substring (point-min) (point-max))))
-
-(defun jao-minibuffer--aligned (&optional w currentp)
- (let* ((msg (if currentp
- (jao-minibuffer--current)
- (format-mode-line (or jao-minibuffer-notification
- jao-minibuffer-info))))
- (msg (propertize (string-trim msg) :minibuffer-message t)))
- (when (not (string-empty-p msg))
- (if jao-minibuffer-align-right-p
- (let* ((mw (if jao-minibuffer-maximized-frames-p
- (frame-width)
- (window-width (minibuffer-window))))
- (w (mod (or w (length (current-message))) mw))
- (w (- mw w jao-minibuffer-right-margin)))
- (if (> w 0) (jao-minibuffer--trim msg w) ""))
- (concat " · " msg)))))
-
-(defun jao-minibuffer--set-message (msg)
- (let ((msg (string-trim (replace-regexp-in-string "\n" " " msg))))
- (concat msg (jao-minibuffer--aligned (length msg) t))))
-
-;;;###autoload
-(defun jao-minibuffer-refresh ()
- (interactive "")
- (with-current-buffer jao-minibuffer--name
- (erase-buffer)
- (insert (or (jao-minibuffer--aligned) ""))))
-
-;;;###autoload
-(defun jao-minibuffer-add-variable (variable-name &optional append)
- (add-to-list 'jao-minibuffer-info `(:eval ,variable-name) append))
-
-(defvar jao-minibuffer--notification-timer nil)
-
-(defun jao-minibuffer--start-notification-timer (timeout)
- (interactive)
- (when jao-minibuffer--notification-timer
- (cancel-timer jao-minibuffer--notification-timer))
- (setq jao-minibuffer--notification-timer
- (run-with-idle-timer (or timeout jao-minibuffer-notification-timeout)
- nil
- 'jao-minibuffer-pop-notification)))
-
-;;;###autoload
-(defun jao-minibuffer-push-notification (msg &optional timeout)
- (setq jao-minibuffer-notification msg)
- (jao-minibuffer--start-notification-timer timeout)
- (jao-minibuffer-refresh))
-
-;;;###autoload
-(defun jao-minibuffer-pop-notification ()
- (interactive)
- (setq jao-minibuffer-notification nil)
- (jao-minibuffer-refresh))
-
-(setq set-message-function #'jao-minibuffer--set-message)
-(setq clear-message-function #'jao-minibuffer-refresh)
-(setq resize-mini-windows nil)
-
-(provide 'jao-minibuffer)
-;;; jao-minibuffer.el ends here
diff --git a/misc/jao-random-album.el b/misc/jao-random-album.el
deleted file mode 100644
index 7158417..0000000
--- a/misc/jao-random-album.el
+++ /dev/null
@@ -1,101 +0,0 @@
-;; jao-random-album.el -- play random albums
-
-;; Copyright (C) 2009, 2010, 2017, 2018, 2019 Jose Antonio Ortega Ruiz
-
-;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
-;; Start date: Sat Jul 04, 2009 13:06
-
-;; This file 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 file 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/>.
-
-(require 'jao-notify)
-
-(defvar jao-random-album-p t)
-(defvar jao-random-lines nil)
-(defvar jao-random-lines-file (expand-file-name "~/.emacs.d/random-lines"))
-(defvar jao-random-album-notify-p t)
-(defvar jao-random-album-notify-icon nil)
-(defvar jao-random-album-skip-lines 2)
-
-(defun jao-random-lines ()
- (or jao-random-lines
- (and (file-exists-p jao-random-lines-file)
- (with-current-buffer
- (find-file-noselect jao-random-lines-file)
- (goto-char (point-min))
- (setq jao-random-lines (read (current-buffer)))))
- (dotimes (n (1- (line-number-at-pos (point-max)))
- jao-random-lines)
- (when (> n jao-random-album-skip-lines)
- (push (1+ n) jao-random-lines)))))
-
-(defun jao-random-lines-save ()
- (with-current-buffer (find-file-noselect jao-random-lines-file)
- (delete-region (point-min) (point-max))
- (insert (format "%s\n" jao-random-lines))
- (save-buffer)))
-
-(defun jao-goto-random-album ()
- (let* ((pos (random (length (jao-random-lines))))
- (line (nth pos jao-random-lines)))
- (setq jao-random-lines (remove line jao-random-lines))
- (jao-random-lines-save)
- (goto-line line)))
-
-
-;; User interface
-(defvar jao-random-album-buffer)
-(defvar jao-random-album-add-tracks-and-play)
-(defvar jao-random-album-stop)
-
-(defun jao-random-album-start ()
- (interactive)
- (setq jao-random-album-p t)
- (jao-random-album-next))
-
-(defun jao-random-album-stop ()
- (interactive)
- (setq jao-random-album-p nil)
- (funcall jao-random-album-stop))
-
-(defun jao-random-album-toggle ()
- (interactive)
- (setq jao-random-album-p (not jao-random-album-p))
- (message "Random album %s"
- (if jao-random-album-p "enabled" "disabled")))
-
-(defun jao-random-album-next ()
- (interactive)
- (with-current-buffer (get-buffer (funcall jao-random-album-buffer))
- (save-excursion
- (jao-goto-random-album)
- (let ((album (string-trim
- (substring-no-properties (thing-at-point 'line) 0 -1))))
- (funcall jao-random-album-add-tracks-and-play)
- (when jao-random-album-notify-p
- (jao-notify album "Next album" jao-random-album-notify-icon))))))
-
-(defun jao-random-album-reset ()
- (interactive)
- (setq jao-random-lines nil)
- (jao-random-lines-save))
-
-(defun jao-random-album-setup (album-buffer add-and-play stop &optional icon)
- (setq jao-random-album-buffer album-buffer
- jao-random-album-add-tracks-and-play add-and-play
- jao-random-album-stop stop
- jao-random-album-notify-icon icon))
-
-
-(provide 'jao-random-album)
-;;; jao-random-album.el ends here
diff --git a/misc/randomsig.el b/misc/randomsig.el
deleted file mode 100644
index e092810..0000000
--- a/misc/randomsig.el
+++ /dev/null
@@ -1,724 +0,0 @@
-;;; randomsig.el --- insert a randomly selected signature
-
-;; Copyright (C) 2001, 2002, 2013 Hans-Jürgen Ficker
-
-;; Emacs Lisp Archive Entry
-;; Author: Hans-Juergen Ficker <hj@backmes.de>
-;; Version: 0.7.0
-;; X-CVS-Version: $Id: randomsig.el,v 1.1.1.1 2003/09/17 22:49:45 jao Exp $
-;; Keywords: mail random signature
-
-;; This file is not currently part of GNU Emacs.
-
-;; 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 2, 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 ; see the file COPYING. If not, write to
-;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
-
-;;; Commentary:
-
-;; This is yet another implementation to insert a randomly choosen
-;; signature into a mail.
-
-;; It is only tested with gnus.
-
-;; To make it work, put the following lines into your ~/.gnus:
-
-;; (require 'randomsig)
-;; (define-key message-mode-map (kbd "C-c s") 'randomsig-replace-sig)
-;; (define-key message-mode-map (kbd "C-c S") 'randomsig-select-sig)
-;; (require 'gnus-sum) ; probably required for `gnus-summary-save-map'
-;; (define-key gnus-summary-save-map "-" 'gnus/randomsig-summary-read-sig)
-;; (setq randomsig-dir "/some/directory")
-;; (setq randomsig-files '("some" "files"))
-;; ;; or (setq randomsig-files (randomsig-search-sigfiles))
-;; ;; or (setq randomsig-files 'randomsig-search-sigfiles)
-;; (setq message-signature 'randomsig-signature)
-
-;; This will also define the shortcut `C-c s' in message-mode to
-;; change the signature, `C-c S' in message-mode to interactively
-;; select the signature to replace the current signature, and `O -' in
-;; gnus-summary-mode to read the signature from the selected mail.
-
-;; `randomsig-files' must be a list of existing files, an existing
-;; file, or a function returning a list of existing files. If these
-;; don't have absolute paths, they are located in `randomsig-dir'.
-
-;; File format: Each file must contain at least one signature.
-;; Signatures are separated with `randomsig-delimiter-pattern'. If
-;; there is only one signature in the file, the delimiter can be
-;; omitted, so real .signature-files can be used.
-
-;; `randomsig-delimiter' is used when inserting new signatures with
-;; `randomsig-message-read-sig' into the signature file. So
-;; `randomsig-delimiter' should match `randomsig-delimiter-pattern'.
-
-;; `randomsig-static-string' is put in front of every random signature
-;; if non-`nil'.
-
-;; The *-read-sig functions read the signature of a message, or use
-;; the marked text, and write it to a signature-file, for which the
-;; name is asked. If the file does not exist, it will be generated.
-;; When called with any prefix, the signatures will be offered to edit
-;; before saving.
-
-;; if `randomsig-replace-sig' is called with any prefix, it will ask
-;; for a file to get the signature from.
-
-;; `randomsig-select-sig' will offer a list of signatures to select
-;; from in an extra buffer. n will jump to the next signature, p to
-;; the previous, RET will insert the selected signature, q will exit
-;; the selection buffer without replacing the current signature, R
-;; will reload the signature-files, and e will open a buffer for
-;; editing the signature at the point. When called with any prefix, it
-;; will ask for a file to get the signatures from
-
-;; `randomsig-search-sigfiles' will search for regular files in
-;; `randomsig-dir', which do not match `randomsig-search-unwanted'. A
-;; subdirectory of `randomsig-dir' can be given as optional argument.
-
-;; Completion will only work for files in `randomsig-files', though
-;; others files can be used, too.
-
-;;; Changelog:
-
-;; 2001/04/12 0.1
-;; * Initial release
-
-;; 2001/04/19 0.2
-;; * inserted `randomsig-delimiter' to add the capability to change
-;; the delimiter between the signatures (thanks to Andreas Büsching
-;; <crunchy@tzi.de>)
-
-;; 2001/04/25 0.3
-;; * new function `randomsig-search-sigfiles', to search all regular files
-;; in directory `randomsig-dir'
-;; * normal signatures only worked, when using only one signature. Fixed.
-
-;; 2001/04/25 0.3.1
-;; * Fixed a bug in `randomsig-search-sigfiles'
-
-;; 2001/04/26 0.3.2
-;; * replaced `point-at-eol' with `line-end-position' (Don't know where
-;; `point-at-eol' is defined)
-;; * require cl
-;; * require message in some functions
-
-;; 2001/07/09 0.3.3
-;; * don't (setq message-signature 'randomsig-signature) by default,
-;; the user can do this in his .gnus
-;; * remove unnecessary optional arguments to `find-file-noselect' to
-;; make it work with XEmacs
-;; (Thanks to Micha Wiedenmann <Micha.Wiedenmann@gmx.net> for both
-;; suggestions)
-;; * documentation updates
-
-;; 2001/07/12 0.3.4
-;; * more fixes for XEmacs
-;; * more documentation Updates
-
-;; 2001/07/20 0.4.0
-;; * new command `randomsig-select-sig' to interactively select a signature
-;; * new mode `randomsig-select-mode' (for `randomsig-select-sig')
-;; * `randomsig-files' can also be function returning a list of
-;; Signature files
-;; * `randomsig-replace-sig' does not remove old signature when interrupted
-
-;; 2001/07/22 0.4.1
-;; * (require 'message) only when needed
-
-;; 2001/08/13 0.5.0
-;; * doesn't require message anymore, so it should work without gnus
-
-;; 2001/08/20 0.5.1
-;; * add (random t) to initialize random seed (thanks to Evgeny
-;; Roubinchtein <evgenyr@cs.washington.edu> for pointing this out
-;; * insert a newline if it is missing at the end of a signature file
-
-;; 2001/09/17 0.5.2
-;; * new variable `randomsig-static-string' (thanks to Raymond Scholz
-;; <rscholz@zonix.de>)
-
-;; 2001/10/01 0.5.3
-;; * Documentation updates
-
-;; 2002/01/20 0.5.99
-;; * It is now possible to edit signatures before saving, or to edit
-;; single signatures from the selection buffer.
-;; * Mark many variables as user option
-;; * randomsig-files-to-list works recursive
-
-;; 2002/03/04 0.6.0
-;; * `randomsig-replace-signature-in-signature-files' should be safer now
-;; * `randomsig-files-to-list' did endless recursion when called
-;; with nil. Fixed.
-;; * Some error-handling for non-existing `randomsig-dir'.
-
-;; 2002/09/21 0.7.0
-;; * most variables customizable
-;; * `randomsig-static-string' works for `randomsig-select-sig', too
-;; (thanks to Mark Trettin <mtr-dev0@gmx.de> for pointing this out)
-;; * documentation updates
-
-(eval-when-compile
- (require 'cl))
-
-
-(defconst randomsig-version "0.7.0")
-
-
-(defvar randomsig-dir "~/.signatures"
- "*Directory for signature-files. See also `randomsig-files'")
-
-
-(defgroup randomsig nil
- "insert a randomly choosen signature into a mail."
- :group 'mail
- :group 'news)
-
-(defcustom randomsig-files '("default")
- "*Files with random signatures.
-This variable may be a list of strings, a string, or a function returning a
-list of strings.
-The files are searched in `randomsig-dir', if they don't have absolute paths.
-The signatures have to be separated by lines matching
-`randomsig-delimiter-pattern' at the beginning."
- :type '(choice
- (repeat
- :tag "List of filenames"
- (string :tag "filename"))
- (function
- :tag "function returning the signature files"
- :value randomsig-search-sigfiles))
- :group 'randomsig)
-
-(defcustom randomsig-delimiter "-- "
- "*delimiter used when adding new signatures in signature file.
-You have to change `randomsig-delimiter-pattern', too, if you change this."
- :type '(string)
- :group 'randomsig)
-
-
-(defcustom randomsig-delimiter-pattern
- (concat "^" (regexp-quote randomsig-delimiter) "$")
- "*Regular expression that matches the delimiters between signatures.
-`randomsig-delimiter' must match `randomsig-delimiter-pattern'."
- :type '(regexp)
- :group 'randomsig)
-
-
-(defcustom randomsig-search-unwanted "\\(/\\|^\\)\\(CVS\\|RCS\\|.*~\\)$"
- "*Regular expression matching unwanted files when scanning with
-`randomsig-search-sigfiles'"
- :type '(regexp)
- :group 'randomsig)
-
-
-(defcustom randomsig-static-string nil
- "*Static string to be inserted above every random signature.
-You probably want to have a newline at the end of it."
- :type '(choice
- (const :tag "none" nil)
- (string))
- :group 'randomsig)
-
-
-(defvar randomsig-buffer-name "*Signatures*"
- "Name for the (temporary) buffer for the signatures")
-
-(defvar randomsig-edit-buffer-name "*Edit Signature*"
- "Name for the (temporary) buffer for editing the signatures")
-
-(defvar randomsig-select-original-buffer nil)
-(defvar randomsig-select-original-position nil)
-
-(defvar randomsig-history nil)
-
-(defvar randomsig-buffer-file-pos-list nil)
-
-(defvar randomsig-select-edit-bufferpos nil)
-
-(defvar randomsig-loaded-files nil)
-
-;; definitions for XEmacs:
-(unless (fboundp 'line-end-position)
- (defalias 'line-end-position 'point-at-eol))
-
-(defun randomsig-mark-active-p ()
- mark-active) ;; jao: region-active-p is defined in GNU Emacs 23 with
- ;; a different meaning
-;;; (if (boundp 'region-active-p)
-
-;;; (region-active-p) ; XEmacs
-
-;;; mark-active)) ; Gnu Emacs
-
-
-(require 'cl)
-
-(random t) ; Initialize random seed
-
-;;; Helper Functions
-
-(defun randomsig-files-to-list (files)
- ;; return a list of strings
- (cond ((listp files) files)
- ((and (symbolp files)
- (fboundp files)) (randomsig-files-to-list (funcall files)))
- ((and (symbolp files)
- (boundp files)) (randomsig-files-to-list (symbol-value files)))
- ((stringp files) (list files))
- (t nil)))
-
-
-(defun randomsig-prompt (&optional prompt)
- ;; Prompt for a signature file.
- (let ((files (randomsig-files-to-list randomsig-files)))
- (completing-read (if prompt prompt "signature: ")
- (mapcar 'list files)
- nil
- nil
- (unless (cdr files) (car files))
- randomsig-history)))
-
-
-(defun randomsig-read-signatures-to-buffer (buffer-name &optional files)
- ;; read the signatures into the signature buffer
- ;; save possibly local variables `randomsig-files' and `randomsig-dir'
- (let ((sigfiles randomsig-files) (sigdir randomsig-dir))
- (if (get-buffer buffer-name)
- (progn
- (set-buffer buffer-name)
- (setq buffer-read-only nil)
- (delete-region (point-min) (point-max)))
- (progn
- (get-buffer-create buffer-name)
- (set-buffer buffer-name)))
- (set (make-local-variable 'randomsig-files) sigfiles)
- (set (make-local-variable 'randomsig-dir) sigdir))
-
- (setq randomsig-buffer-file-pos-list nil)
-
- (unless files
- (setq files randomsig-files))
-
- (setq randomsig-loaded-files files)
-
- ;; get a list with file names of signature files
- (let ((sigfiles (randomsig-files-to-list files)))
- ;; Insert all files into the newly created buffer
- (mapcar
- (lambda (fname)
-
- (let ((pos (point-max)))
- ;;(add-to-list 'randomsig-buffer-file-pos-list (cons fname pos) t)
- ; this does not work with XEmacs
- (goto-char pos)
- (insert-file-contents (expand-file-name fname randomsig-dir))
- ;; No delimiter at the beginning? Insert one.
- (unless (string-match randomsig-delimiter-pattern
- (buffer-substring (goto-char pos)
- (line-end-position)))
- (goto-char pos)
- (insert randomsig-delimiter)
- (insert "\n")
- ;; Correct position...
- (setq pos (+ pos (length randomsig-delimiter) 1)))
-
- (setq randomsig-buffer-file-pos-list
- (append randomsig-buffer-file-pos-list
- (list (cons fname pos))))
- (goto-char (point-max))
- (unless (and (char-before)
- (char-equal (char-before) ?\n)) ; Newline?
- (insert "\n"))))
- sigfiles)
- (set-buffer-modified-p nil)
- (setq buffer-read-only t)
- (current-buffer)))
-
-
-
-(defun randomsig-insert-signature (sig)
- ;; Insert SIG as signature in current buffer
- (save-excursion
- (goto-char (point-max))
- (insert "\n-- \n" sig)))
-
-
-
-(defun randomsig-goto-signature ()
-;; This function is stolen fom message-goto signature.
-;; Go to beginnig of the signature, and return t.
-;; If there is no signature in current buffer, go to end of buffer,
-;; and return nil.
- (goto-char (point-min))
- (if (re-search-forward "^-- $" nil t)
- (progn
- (forward-line 1)
- t)
- (progn
- (goto-char (point-max))
- nil)))
-
-
-
-(defun randomsig-replace-signature (sig)
- ;; Replace the current signature with SIG
- (save-excursion
- (when (randomsig-goto-signature)
- (forward-line -1)
- (backward-char)
- (delete-region (point) (point-max)))
-
- (randomsig-insert-signature sig)))
-
-
-(defun randomsig-signature (&optional files)
- "Return a randomly choosen signature.
-If FILES is non-nil, a signature out of FILES will be choosen.
-Else a signature out of `randomsig-files' will be choosen."
- (save-excursion
-
- (randomsig-read-signatures-to-buffer randomsig-buffer-name files)
-
- (goto-char (point-min))
- (let '(count 0) 'selected
-
- ;; Count number of signatures
- (while (search-forward-regexp randomsig-delimiter-pattern nil t)
- (setq count (1+ count)))
-
- ;; Select random signature out out these
- (setq selected (1+ (random count)))
- (goto-char (point-min))
- (if (search-forward-regexp randomsig-delimiter-pattern nil t selected)
- (forward-char))
-
- ;; Cut signature and return it
- (let '(here (point)) 'signature-string
-
- (if (not (search-forward-regexp randomsig-delimiter-pattern
- nil t))
- (goto-char (point-max))
- (beginning-of-line))
- (setq signature-string
- (concat randomsig-static-string
- (buffer-substring here (point))))
- (kill-buffer randomsig-buffer-name)
- signature-string))))
-
-
-(defun randomsig-replace-sig (arg)
- "Replace the actual signature with a new one.
-When called with prefix, read the filename of the signature-file
-that should be used"
- (interactive "P")
- (save-excursion
-
- (randomsig-replace-signature
- (randomsig-signature
- (if arg
- (randomsig-prompt "read from signature-lib: ")
- randomsig-files)))))
-
-
-
-(defun randomsig-message-read-sig (arg)
- "Get the signature of current message and copy it to a file.
-If mark is active, get the marked region instead.
-When called with prefix, let the user edit the signature before saving"
- (interactive "P")
- (save-excursion
- (let '(signature-string
- (if (randomsig-mark-active-p)
-
- (buffer-substring (point) (mark))
-
- (progn
- (if (randomsig-goto-signature)
- (let `(here (point))
- (goto-char (point-max))
- (while (char-equal (char-before) 10)
- (backward-char))
- (buffer-substring here (point)))
- nil))))
- (when signature-string
- (if arg
- (progn
- ;; make sure this is nil...
- (setq randomsig-select-edit-bufferpos nil)
- (randomsig-edit signature-string))
- (randomsig-write-signature signature-string))))))
-
-
-(defun randomsig-write-signature (signature-string)
- (set-buffer (find-file-noselect
- (expand-file-name
- (randomsig-prompt "Write to signature-lib: ")
- randomsig-dir)))
-
- (goto-char (point-max))
- (insert (concat randomsig-delimiter "\n"))
- (insert signature-string)
- (insert "\n")
- (save-buffer))
-
-
-(defun gnus/randomsig-summary-read-sig (arg)
- "Get the signature of current message and copy it to a file"
- (interactive "P")
- (progn ;save-excursion
- ;; FIXME: Doesn't return to summary buffer (save-excursion should do this)
- (gnus-summary-select-article-buffer)
- (randomsig-message-read-sig arg)))
-
-
-(defun randomsig-search-sigfiles (&optional file)
- "Scan `randomsig-dir' and its subdirectories for regular files.
-If FILE is given, only FILE and its subdirectory will be searched."
- (unless (file-exists-p randomsig-dir)
- (error "\"%s\" does not exist" randomsig-dir))
- (unless (file-directory-p randomsig-dir)
- (error "\"%s\" is not a directory" randomsig-dir))
- (unless file
- (setq file ""))
-
- (if (or (string-match "\\(/\\|^\\)\\(\\.\\|\\.\\.\\)$" file)
- (string-match randomsig-search-unwanted file))
- ;; unwanted...
- nil
-
- (let '(path (expand-file-name file randomsig-dir))
- (if (file-directory-p path)
- (mapcan (lambda (f)
- (randomsig-search-sigfiles (if (string= file "")
- f
- (concat file "/" f))))
- (directory-files path))
- (if (file-regular-p path)
- (list file)
- nil)))))
-
-
-;;; Commands/Function for randomsig-edit-mode
-
-(defun randomsig-edit (signature)
- (if (get-buffer randomsig-edit-buffer-name)
- (kill-buffer randomsig-edit-buffer-name))
- (switch-to-buffer (get-buffer-create randomsig-edit-buffer-name))
- (insert signature)
- (goto-char (point-min))
- (set-buffer-modified-p t)
- (setq buffer-read-only nil)
- (randomsig-edit-mode))
-
-
-
-(defun randomsig-replace-signature-in-signature-files (signature)
- (if (not randomsig-select-edit-bufferpos)
- (error "Not in select buffer previously"))
- (set-buffer randomsig-buffer-name)
- (let* ((fname (randomsig-buffer-which-file))
- (sig_end
- ;; point in selection buffer, where signature ends
- (progn
- (if (search-forward-regexp randomsig-delimiter-pattern nil t)
- (search-backward-regexp randomsig-delimiter-pattern nil nil))
- (point)))
- (sig_start
- ;; point in selection buffer, where signature starts
- (progn
- (if (search-backward-regexp randomsig-delimiter-pattern nil t)
- (progn
- (search-forward-regexp randomsig-delimiter-pattern nil nil)
- (forward-char)))
- (point)))
- (f_start
- ;; point in selection buffer, where signature file starts
- (- (cdr (assoc fname randomsig-buffer-file-pos-list))
- (point-min)))
- ;; point in file, where Signature starts/ends
- (f_sig_start (- sig_start f_start))
- (f_sig_end (- sig_end f_start))
- ;; old signature
- (old_sig (randomsig-signature-at-point)))
- (set-buffer (find-file-noselect (expand-file-name fname randomsig-dir)))
-
- (if (not (string= old_sig (buffer-substring f_sig_start f_sig_end)))
- (error "Signature file has changed"))
- (delete-region f_sig_start f_sig_end)
- (goto-char f_sig_start)
- (insert signature)
- (save-buffer))
- (randomsig-select-reload))
-
-
-(defun randomsig-edit-done ()
- (interactive)
- (let ((signature-string (buffer-string))
- (edit-buffer (current-buffer)))
- (if randomsig-select-edit-bufferpos
- (randomsig-replace-signature-in-signature-files signature-string)
- (randomsig-write-signature signature-string))
- (kill-buffer edit-buffer)))
-
-
-(define-derived-mode randomsig-edit-mode text-mode
- "Randomsig Edit"
- "A major mode for editing signatures.
-You most likely do not want to call `randomsig-edit-mode' directly.
-
-\\{randomsig-edit-mode-map}"
- (define-key randomsig-edit-mode-map
- (kbd "C-c C-c") 'randomsig-edit-done))
-
-
-;;; Commands for randomsig-select-mode
-
-(defun randomsig-select-next ()
- "Goto next signature."
- (interactive)
- (if (search-forward-regexp randomsig-delimiter-pattern nil t)
- (forward-char)))
-
-
-(defun randomsig-select-prev ()
- "Goto next signature."
- (interactive)
- (if (search-backward-regexp randomsig-delimiter-pattern nil t 2)
- (forward-line)))
-
-
-(defun randomsig-signature-at-point()
- ;; Return the signature at current cursor position
- (save-excursion
- (if (search-backward-regexp randomsig-delimiter-pattern nil t)
- (forward-line))
- (let ((beginning (point)))
- (if (search-backward-regexp randomsig-delimiter-pattern nil t)
- (forward-line))
- (if (not (search-forward-regexp randomsig-delimiter-pattern
- nil t))
- (goto-char (point-max))
- (beginning-of-line))
- (buffer-substring beginning (point)))))
-
-
-(defun randomsig-select-replace ()
- "Replace the signature in `randomsig-select-original-buffer'
-with the signature at the current position, and quit selection."
- (interactive)
- (let ((sig (randomsig-signature-at-point)))
- (kill-buffer randomsig-buffer-name)
- (switch-to-buffer randomsig-select-original-buffer)
- (randomsig-replace-signature (concat randomsig-static-string sig))
- (goto-char randomsig-select-original-position)))
-
-
-(defun randomsig-select-quit ()
- "Quit the signature-buffer without selection of a signature."
- (interactive)
- (kill-buffer randomsig-buffer-name))
-
-
-(defun randomsig-select-abort ()
- "Abort the selection from signature-buffer."
- (interactive)
- (ding)
- (kill-buffer randomsig-buffer-name))
-
-
-(defun randomsig-select-reload ()
- "Reload the current randomsig-buffer"
- (interactive)
- (set-buffer randomsig-buffer-name)
- (let ((pos (point)))
- (randomsig-read-signatures-to-buffer randomsig-buffer-name
- randomsig-loaded-files)
- (goto-char pos)))
-
-
-(defun randomsig-select-edit ()
- "Edit the signature at point"
- (interactive)
- (setq randomsig-select-edit-bufferpos (point))
- (randomsig-edit (randomsig-signature-at-point)))
-
-
-(defun randomsig-buffer-which-file ()
- (let ((p 0)
- (fname "")
- (l randomsig-buffer-file-pos-list))
- (while (progn
- (setq fname (car (car l)))
- (setq l (cdr l))
- (setq p (cdr (car l)))
- (and l (<= p (point)))))
- fname))
-
-
-(define-derived-mode randomsig-select-mode fundamental-mode
- "Randomsig Select"
- "A major mode for selecting signatures.
-You most likely do not want to call `randomsig-select-mode' directly; use
-`randomsig-select-sig' instead.
-
-\\{randomsig-select-mode-map}"
-
- (define-key randomsig-select-mode-map (kbd "n") 'randomsig-select-next)
- (define-key randomsig-select-mode-map (kbd "p") 'randomsig-select-prev)
- (define-key randomsig-select-mode-map (kbd "?") 'describe-mode)
- (define-key randomsig-select-mode-map (kbd "h") 'describe-mode)
- (define-key randomsig-select-mode-map (kbd "RET") 'randomsig-select-replace)
- (define-key randomsig-select-mode-map (kbd "R") 'randomsig-select-reload)
- (define-key randomsig-select-mode-map (kbd "e") 'randomsig-select-edit)
- (define-key randomsig-select-mode-map (kbd "q") 'randomsig-select-quit)
- (define-key randomsig-select-mode-map (kbd "C-g") 'randomsig-select-abort)
-
- ;; Experimental: show the file
- ;; FIXME: this does only work for Gnu Emacs 21
- (and (not (boundp 'xemacs-codename))
- (>= emacs-major-version 21)
- (setq mode-line-buffer-identification
- '(:eval (format "%-12s"
- (concat "["
- (randomsig-buffer-which-file)
- "]"))))))
-
-(defun randomsig-select-sig (arg)
- "Select a new signature from a list.
-If called with prefix argument, read the filename of the signature-file
-that should be used."
- (interactive "P")
-
- (setq randomsig-select-original-buffer (current-buffer))
- (setq randomsig-select-original-position (point))
-
-
- (switch-to-buffer
- (randomsig-read-signatures-to-buffer
- randomsig-buffer-name
- (if arg
- (randomsig-prompt "read from signature-lib: ")
- randomsig-files)))
- (goto-char 0)
- (forward-line)
- (randomsig-select-mode))
-
-
-
-(provide 'randomsig)
-
-
-;;; randomsig.el ends here