From: Magnus H. <leg...@us...> - 2007-05-08 12:22:34
|
Update of /cvsroot/emacs-jabber/emacs-jabber In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv32068 Modified Files: jabber-history.el Log Message: Revision: ma...@fr...--2005/emacs-jabber--cvs-head--0--patch-358 Creator: Magnus Henoch <ma...@fr...> Add jabber-history-move-to-per-user Yes, my design decision in 2004 was probably wrong ⺠Index: jabber-history.el =================================================================== RCS file: /cvsroot/emacs-jabber/emacs-jabber/jabber-history.el,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- jabber-history.el 5 Feb 2007 21:59:02 -0000 1.26 +++ jabber-history.el 8 May 2007 12:22:26 -0000 1.27 @@ -1,7 +1,7 @@ ;; jabber-history.el - recording message history +;; Copyright (C) 2004, 2007 - Magnus Henoch - ma...@fr... ;; Copyright (C) 2004 - Mathias Dahl -;; Copyright (C) 2004 - Magnus Henoch - ma...@fr... ;; This file is a part of jabber.el. @@ -241,6 +241,48 @@ (concat "^" (regexp-quote (jabber-jid-user jid)) "\\(/.*\\)?$") (jabber-history-filename jid))) +(defun jabber-history-move-to-per-user () + "Migrate global history to per-user files." + (interactive) + (when (file-directory-p jabber-history-dir) + (error "Per-user history directory already exists")) + (make-directory jabber-history-dir) + (let ((jabber-use-global-history nil)) + (with-temp-buffer + (let ((coding-system-for-read 'utf-8)) + (insert-file-contents jabber-global-history-filename)) + (let ((progress-reporter + (when (fboundp 'make-progress-reporter) + (make-progress-reporter "Migrating history..." + (point-min) (point-max)))) + ;;(file-table (make-hash-table :test 'equal)) + ;; Keep track of blocks of entries pertaining to the same JID. + current-jid jid-start) + (while (not (eobp)) + (let* ((start (point)) + (end (progn (forward-line) (point))) + (line (buffer-substring start end)) + (parsed (car (read-from-string line))) + (jid (if (string= (aref parsed 2) "me") + (aref parsed 3) + (aref parsed 2)))) + ;; Whenever there is a change in JID... + (when (not (equal jid current-jid)) + (when current-jid + ;; ...save data for previous JID... + (let ((history-file (jabber-history-filename current-jid))) + (write-region jid-start start history-file t 'quiet))) + ;; ...and switch to new JID. + (setq current-jid jid) + (setq jid-start start)) + (when (fboundp 'progress-reporter-update) + (progress-reporter-update progress-reporter (point))))) + ;; Finally, save the last block, if any. + (when current-jid + (let ((history-file (jabber-history-filename current-jid))) + (write-region jid-start (point-max) history-file t 'quiet)))))) + (message "Done. Please change `jabber-use-global-history' now.")) + (provide 'jabber-history) ;; arch-tag: 0AA0C235-3FC0-11D9-9FE7-000A95C2FCD0 |