2017-10-17 10:34:56 +03:00
|
|
|
;;; idec-mode.el --- This file part of GNU Emacs client for IDEC network
|
|
|
|
|
|
|
|
;; Copyright (c) 2017 Denis Zheleztsov
|
|
|
|
|
|
|
|
;; Author: Denis Zheleztsov <difrex.punk@gmail.com>
|
|
|
|
;; Keywords: lisp,network,IDEC
|
|
|
|
;; Version: 0.1
|
|
|
|
|
|
|
|
;; 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; In active developent.
|
|
|
|
;; Fetched node must be support modern IDEC extensions like /list.txt, /x/c, etc.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2017-11-03 10:55:04 +03:00
|
|
|
(require 'idec)
|
|
|
|
(require 'idec-online)
|
|
|
|
|
|
|
|
(defgroup idec nil
|
|
|
|
"IDEC configuration."
|
|
|
|
:group 'network)
|
|
|
|
|
|
|
|
;; Not used
|
|
|
|
(defcustom idec-nodes-list
|
2018-06-29 09:44:31 +03:00
|
|
|
"http://idec.spline-online.tk/,https://ii-net.tk/ii/ii-point.php?q=/;
|
|
|
|
List(comma separated) of IDEC nodes;
|
|
|
|
Currently not used."
|
2017-11-03 10:55:04 +03:00
|
|
|
:type 'string
|
|
|
|
:group 'idec)
|
|
|
|
|
2018-06-26 09:35:35 +03:00
|
|
|
(defcustom idec-primary-node ""
|
2017-11-03 10:55:04 +03:00
|
|
|
"Primary node to send messages."
|
|
|
|
:type 'string
|
|
|
|
:group 'idec)
|
|
|
|
|
|
|
|
;; Never used at this time.
|
|
|
|
(defcustom idec-use-list-txt t
|
|
|
|
"Use /list.txt extension."
|
2018-06-29 09:44:31 +03:00
|
|
|
:type 'boolean
|
2017-11-03 10:55:04 +03:00
|
|
|
:group 'idec)
|
|
|
|
|
|
|
|
(defcustom idec-smart-fetch t
|
2018-06-29 09:44:31 +03:00
|
|
|
"Enable smart fetching;
|
2017-11-03 10:55:04 +03:00
|
|
|
Download only new messages; Not implemented."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'idec)
|
|
|
|
|
|
|
|
(defcustom idec-download-limit "50"
|
|
|
|
"Limit of download messages;
|
|
|
|
Not used if `idec-smart-fetching' is not nil."
|
|
|
|
:type 'string
|
|
|
|
:group 'idec)
|
|
|
|
|
|
|
|
(defcustom idec-download-offset "-50"
|
|
|
|
"Offset of download messages;
|
|
|
|
Not used if `idec-smart-fetching' is not nil."
|
|
|
|
:type 'string
|
|
|
|
:group 'idec)
|
|
|
|
|
2018-06-26 09:57:21 +03:00
|
|
|
(defcustom idec-echo-subscriptions "idec.talks,pipe.2032"
|
2017-11-03 10:55:04 +03:00
|
|
|
"List of subribes echoes."
|
|
|
|
:type 'string
|
|
|
|
:group 'idec)
|
|
|
|
|
2018-06-29 09:44:31 +03:00
|
|
|
(defcustom idec-mail-dir (concat user-emacs-directory "/idec-mail")
|
2017-11-03 10:55:04 +03:00
|
|
|
"Directory to store mail."
|
|
|
|
:type 'string
|
|
|
|
:group 'idec)
|
|
|
|
|
|
|
|
(defcustom idec-online-download-limit "0"
|
|
|
|
"Download limit on online browsing;
|
|
|
|
Default to `idec-download-lmit'"
|
|
|
|
:type 'string
|
|
|
|
:group 'idec)
|
|
|
|
|
|
|
|
(defcustom idec-online-download-offset "0"
|
|
|
|
"Download limit on online browsing;
|
|
|
|
Default to `idec-download-offset'"
|
|
|
|
:type 'string
|
|
|
|
:group 'idec)
|
|
|
|
|
2018-06-28 21:38:30 +03:00
|
|
|
(defcustom idec-desc-local-echo-sort nil
|
|
|
|
"Sort order in local echo display mode."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'idec)
|
|
|
|
|
2017-11-03 10:55:04 +03:00
|
|
|
(defgroup idec-accounts nil
|
|
|
|
"IDEC accounts settings."
|
|
|
|
:group 'idec)
|
|
|
|
|
|
|
|
(defcustom idec-account-nick ""
|
|
|
|
"Account nickname."
|
|
|
|
:type 'string
|
|
|
|
:group 'idec-accounts)
|
|
|
|
|
|
|
|
(defcustom idec-account-node ""
|
|
|
|
"Node to send messages."
|
|
|
|
:type 'string
|
|
|
|
:group 'idec-accounts)
|
|
|
|
|
|
|
|
(defcustom idec-account-auth ""
|
|
|
|
"Account authstring."
|
|
|
|
:type 'string
|
|
|
|
:group 'idec-accounts)
|
|
|
|
|
|
|
|
;; END OF CUSTOMIZATION
|
|
|
|
;; ;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
;; VARIABLES
|
|
|
|
;; ;;;;;;;;;
|
|
|
|
|
|
|
|
(defvar smart-download-limit nil
|
|
|
|
"Used with `idec-smart-fetch'.")
|
|
|
|
|
|
|
|
(defvar smart-download-offset nil
|
|
|
|
"Used with `idec-smart-fetch'.")
|
|
|
|
|
|
|
|
(defvar new-messages-list nil
|
|
|
|
"New messages for display.")
|
|
|
|
|
|
|
|
(setq idec-online-download-limit idec-download-limit)
|
|
|
|
(setq idec-online-download-offset idec-download-offset)
|
|
|
|
|
|
|
|
;; END OF VARIABLES
|
|
|
|
;; ;;;;;;;;;;;;;;;;
|
|
|
|
|
2017-10-17 10:34:56 +03:00
|
|
|
;; MODE
|
|
|
|
;; ;;;;
|
|
|
|
|
|
|
|
(defun idec-close-message-buffer ()
|
|
|
|
"Close buffer with message."
|
|
|
|
(kill-this-buffer))
|
|
|
|
|
|
|
|
(defvar idec-mode-hook nil)
|
|
|
|
|
|
|
|
(defvar idec-mode-map
|
2017-10-20 13:52:38 +03:00
|
|
|
(let ((map (make-sparse-keymap)))
|
2018-06-29 09:44:31 +03:00
|
|
|
(define-key map "\C-c \C-c" 'kill-this-buffer)
|
|
|
|
(define-key map "\C-c \C-n" 'idec-next-message)
|
|
|
|
(define-key map "\C-c \C-b" 'idec-previous-message)
|
|
|
|
(define-key map "\C-c \C-e" 'idec-new-message)
|
2017-10-17 10:34:56 +03:00
|
|
|
map)
|
|
|
|
"Keymapping for IDEC mode.")
|
|
|
|
|
2017-10-20 13:52:38 +03:00
|
|
|
(defvar idec-mode-syntax-table
|
|
|
|
(let ((st (make-syntax-table)))
|
|
|
|
(modify-syntax-entry ?# "<" st)
|
|
|
|
(modify-syntax-entry ?\n ">" st)
|
|
|
|
st))
|
|
|
|
|
2017-10-17 10:34:56 +03:00
|
|
|
(defconst idec-font-lock-keywords-1
|
|
|
|
(list
|
|
|
|
'("\\(ID:.*\\)" . font-lock-function-name-face)
|
|
|
|
'("\\<\\(\\(?:Echo\\|From\\|Subj\\|T\\(?:ime\\|o\\)\\):\\)\\>" . font-lock-function-name-face))
|
|
|
|
"Minimal highlighting expressions for IDEC mode.")
|
|
|
|
|
|
|
|
(defconst idec-font-lock-keywords-2
|
|
|
|
(append idec-font-lock-keywords-1 (list
|
|
|
|
'("\\<\\(>>?.*\\)\s\\>" . font-lock-comment-face)))
|
|
|
|
"Quotes highligting for IDEC mode.")
|
|
|
|
|
2017-10-23 10:44:45 +03:00
|
|
|
(defvar idec-font-lock-keywords idec-font-lock-keywords-1
|
|
|
|
;; '(("ID" (1 font-lock-function-name-face)))
|
2017-10-17 10:34:56 +03:00
|
|
|
"Default highlighting expressions for IDEC mode.")
|
|
|
|
|
|
|
|
;; Mode function
|
2017-10-23 10:44:45 +03:00
|
|
|
(define-generic-mode
|
|
|
|
'idec
|
|
|
|
'("//" ">" "ЗЫ" "# ")
|
|
|
|
'("ii://" "ID" "$subj" "сабж" "субж"
|
|
|
|
"Subject" "From" "To" "Echo" "At")
|
|
|
|
'(("=" . 'font-lock-operator)
|
|
|
|
(";" . 'font-lock-builtin))
|
2018-06-29 09:44:31 +03:00
|
|
|
'("\\.*idec\\.*|\\.*Idec\\.*|\\.*IDEC\\.*$")
|
2017-10-23 10:44:45 +03:00
|
|
|
nil)
|
|
|
|
|
|
|
|
(define-derived-mode org-idec text-mode "IDEC"
|
2017-10-17 10:34:56 +03:00
|
|
|
"Major mode for view and editing IDEC messages."
|
2017-10-20 13:52:38 +03:00
|
|
|
:syntax-table idec-mode-syntax-table
|
2017-10-23 10:44:45 +03:00
|
|
|
(setq-local comment-start "/{2} ")
|
2017-10-20 13:52:38 +03:00
|
|
|
(setq-local font-lock-defaults
|
|
|
|
'(idec-font-lock-keywords))
|
2017-10-17 10:34:56 +03:00
|
|
|
(use-local-map idec-mode-map)
|
2017-10-20 13:52:38 +03:00
|
|
|
(setq-local indent-line-function 'org-indent-line)
|
2017-10-17 10:34:56 +03:00
|
|
|
(setq imenu-generic-expression "*IDEC")
|
2017-10-20 13:52:38 +03:00
|
|
|
(setq mode-name "[IDEC]")
|
2017-10-17 10:34:56 +03:00
|
|
|
(run-hooks 'idec-mode-hook))
|
|
|
|
|
2017-10-23 10:44:45 +03:00
|
|
|
(defun idec-mode ()
|
|
|
|
"Major mode for view and editing IDEC messages."
|
|
|
|
(interactive)
|
|
|
|
(kill-all-local-variables)
|
|
|
|
;; Mode definition
|
|
|
|
(set-syntax-table idec-mode-syntax-table)
|
|
|
|
(use-local-map idec-mode-map)
|
|
|
|
;; (font-lock-add-keywords 'idec-mode '(idec-font-lock-keywords))
|
|
|
|
;; (set (make-local-variable 'font-lock-defaults) '(idec-font-lock-keywords))
|
|
|
|
(setq major-mode 'idec-mode)
|
|
|
|
(setq mode-name "[IDEC]")
|
|
|
|
(setq imenu-generic-expression "*IDEC")
|
|
|
|
(run-hooks 'idec-mode-hook))
|
2017-10-20 13:52:38 +03:00
|
|
|
|
2017-11-03 10:55:04 +03:00
|
|
|
(defun idec-mark-all-as-read (&optional echo)
|
|
|
|
"Mark all messages in ECHO as read."
|
|
|
|
(interactive)
|
|
|
|
(if (not echo)
|
|
|
|
(mark-all-messages-as-read (read-string "Enter echo name: "))
|
|
|
|
(mark-all-messages-as-read echo)))
|
|
|
|
|
|
|
|
(defun idec-local-browse (&optional checkpoint)
|
|
|
|
"Browse local mail from `idec-mail-dir';
|
|
|
|
optionaly return cursor to CHECKPOINT."
|
|
|
|
(interactive)
|
|
|
|
(get-buffer-create "*IDEC: INBOX*")
|
|
|
|
(with-output-to-temp-buffer (get-buffer-create "*IDEC: INBOX*")
|
|
|
|
(switch-to-buffer "*IDEC: INBOX*")
|
|
|
|
(save-excursion
|
|
|
|
(dolist (echo (get-local-echoes))
|
|
|
|
(if echo
|
|
|
|
(let (unread start end)
|
|
|
|
;; Echo name with unread messages
|
|
|
|
;; ii.test.14 (5)*
|
|
|
|
(insert-button echo
|
2017-11-12 11:15:55 +03:00
|
|
|
'action (lambda (x) (idec-browse-local-echo (button-get x 'echo)))
|
2017-11-03 10:55:04 +03:00
|
|
|
'echo echo
|
|
|
|
'(face nil))
|
|
|
|
|
|
|
|
(beginning-of-line)
|
|
|
|
(setq start (point))
|
|
|
|
(end-of-line)
|
|
|
|
(setq end (point))
|
|
|
|
(add-text-properties start end '(comment t face '(:foreground "light green")))
|
|
|
|
|
|
|
|
(princ (concat (dots echo)
|
|
|
|
"("
|
|
|
|
(number-to-string (get-echo-messages-count echo))
|
|
|
|
")"))
|
|
|
|
|
|
|
|
(setq unread (get-echo-unread-messages echo))
|
|
|
|
(when (> unread 0)
|
|
|
|
(princ "*"))
|
|
|
|
(princ " ")
|
|
|
|
|
|
|
|
;; [New message] button
|
|
|
|
(princ "\t[")
|
|
|
|
(insert-button "New message"
|
|
|
|
'action (lambda (x) (idec-new-message (button-get x 'echo)))
|
|
|
|
'echo echo)
|
|
|
|
(princ "]\t[")
|
|
|
|
;; [Mark read] button
|
|
|
|
(insert-button "Mark read"
|
|
|
|
'action (lambda (x) (mark-all-as-read (button-get x 'echo) (button-get x 'point)))
|
|
|
|
'echo echo
|
|
|
|
'point (point))
|
|
|
|
(princ "]\n"))
|
|
|
|
(message (concat "IDEC: FUUUUUU <" echo ">")))
|
|
|
|
))
|
|
|
|
(add-text-properties (point-min) (point-max) 'read-only))
|
|
|
|
(if checkpoint
|
|
|
|
(goto-char checkpoint))
|
|
|
|
(idec-mode))
|
|
|
|
|
2017-11-12 11:15:55 +03:00
|
|
|
(defun idec-browse-local-echo (&optional echo)
|
2017-11-03 10:55:04 +03:00
|
|
|
"Get messages from local ECHO."
|
|
|
|
(interactive)
|
|
|
|
(if (not echo)
|
|
|
|
(setq echo (read-string "Enter echo name: ")))
|
2018-06-27 15:08:32 +03:00
|
|
|
(let (longest)
|
|
|
|
(setq longest (longest-local-echo-subj echo))
|
|
|
|
(with-output-to-temp-buffer (get-buffer-create (concat "*IDEC: INBOX->(" echo ")") )
|
|
|
|
(switch-to-buffer (concat "*IDEC: INBOX->(" echo ")"))
|
|
|
|
(let (counter)
|
|
|
|
(setq counter 0)
|
|
|
|
(dolist (msg (get-echo-messages echo))
|
2018-06-28 14:12:43 +03:00
|
|
|
(insert-button (gethash "subj" msg)
|
2018-06-27 15:08:32 +03:00
|
|
|
'action (lambda (x) (display-message-hash (button-get x 'msg-hash)))
|
|
|
|
'subj (gethash "subj" msg)
|
|
|
|
'help-echo (concat "Read message *" (gethash "subj" msg) "*")
|
|
|
|
'msg-hash msg)
|
2018-06-28 14:12:43 +03:00
|
|
|
(princ (make-string
|
|
|
|
(- longest
|
|
|
|
(length (gethash "subj" msg)))
|
|
|
|
? ))
|
2018-06-27 15:08:32 +03:00
|
|
|
(princ (concat " " (gethash "time" msg)))
|
|
|
|
(princ (concat "\t" (gethash "author" msg) "\n")))
|
|
|
|
(idec-mode)))))
|
2017-11-03 10:55:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
;; NAVIGATION FUNCTIONS
|
|
|
|
;; ;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(defun idec-next-message ()
|
|
|
|
"Show next message."
|
|
|
|
(interactive)
|
|
|
|
(kill-this-buffer)
|
|
|
|
(forward-button 1)
|
|
|
|
(push-button))
|
|
|
|
|
|
|
|
(defun idec-previous-message ()
|
|
|
|
"Show next message."
|
|
|
|
(interactive)
|
|
|
|
(kill-this-buffer)
|
|
|
|
(backward-button 1)
|
|
|
|
(push-button))
|
|
|
|
|
|
|
|
;; END OF NAVIGATION FUNCTIONS
|
|
|
|
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
|
|
(defun idec-load-new-messages ()
|
|
|
|
"Load new messages from IDEC `idec-primary-node'."
|
|
|
|
(interactive)
|
|
|
|
(defvar current-echo nil)
|
|
|
|
(setq new-messages-list (make-hash-table :test 'equal))
|
|
|
|
(let (msgid-for-download)
|
|
|
|
(setq msgid-for-download (make-hash-table :test 'equal))
|
|
|
|
(dolist (line (split-string (download-subscriptions) "\n"))
|
|
|
|
(if (string-match "\\." line)
|
|
|
|
(and (setq current-echo line)
|
|
|
|
(store-echo-counter line))
|
|
|
|
(when (and ;; (check-message-in-echo line current-echo)
|
2018-06-27 15:08:32 +03:00
|
|
|
(> (length line) 1)
|
|
|
|
(check-message-in-db line current-echo))
|
2017-11-03 10:55:04 +03:00
|
|
|
(when (not (string= "" line))
|
|
|
|
(puthash line current-echo msgid-for-download)))))
|
|
|
|
(download-message msgid-for-download))
|
|
|
|
;; (print (hash-table-count new-messages-list))
|
|
|
|
;; (message (gethash "id" (nth 0 new-messages-list)))
|
|
|
|
(display-new-messages)
|
|
|
|
)
|
|
|
|
|
|
|
|
(defun idec-new-message (&optional echo)
|
|
|
|
"Make new message to ECHO."
|
|
|
|
(interactive)
|
|
|
|
(if (not echo) (edit-new-message (read-string "Echo: "))
|
|
|
|
(edit-new-message echo)))
|
|
|
|
|
|
|
|
;; Online
|
|
|
|
(defun idec-online-browse ()
|
|
|
|
"Load echoes list.txt from node `idec-primary-node'."
|
|
|
|
(interactive)
|
|
|
|
(idec-fetch-echo-list (concat idec-primary-node "list.txt")))
|
|
|
|
|
|
|
|
(defun idec-online-browse-hidden ()
|
|
|
|
"Browse hidden echo."
|
|
|
|
(interactive)
|
|
|
|
(load-echo-messages (read-string "Enter echo name: ") t))
|
|
|
|
|
2017-10-17 10:34:56 +03:00
|
|
|
|
|
|
|
;;; idec-mode.el ends here
|
2017-11-03 10:55:04 +03:00
|
|
|
|
|
|
|
(provide 'idec-mode)
|