Select echo messages fucntion

This commit is contained in:
Denis Zheleztsov 2017-10-23 10:44:45 +03:00
parent a208a5192a
commit fc60b7d2f3
5 changed files with 104 additions and 42 deletions

View File

@ -198,7 +198,7 @@
'action (lambda (x) (send-reply-message (button-get x 'msg))) 'action (lambda (x) (send-reply-message (button-get x 'msg)))
'msg answer-hash) 'msg answer-hash)
(goto-char p) (goto-char p)
(idec-mode))) (org-idec)))
;; END OF ANSWERS ;; END OF ANSWERS
@ -225,7 +225,7 @@
'action (lambda (x) (send-new-message (button-get x 'msg-echo))) 'action (lambda (x) (send-new-message (button-get x 'msg-echo)))
'msg-echo echo) 'msg-echo echo)
(goto-char p)) (goto-char p))
(idec-mode)) (org-idec))
(provide 'idec-answers) (provide 'idec-answers)

View File

@ -142,6 +142,38 @@ unread by default, but you can MARK-READ it."
[:select [id] [:select [id]
:from messages]))) :from messages])))
(defun make-hash-from-msg-list (msg-list)
"Return hash table maded from MSG-LIST."
(let (msg-hash)
(if (and
(listp msg-list)
(> (length msg-list) 0))
(let ()
(setq msg-hash (make-hash-table :test 'equal))
(puthash "id" (nth 0 l) msg-hash)
(puthash "tags" (nth 1 l) msg-hash)
(puthash "author" (nth 2 l) msg-hash)
(puthash "recipient" (nth 3 l) msg-hash)
(puthash "repto" (nth 4 l) msg-hash)
(puthash "echo" (nth 5 l) msg-hash)
(puthash "subj" (nth 6 l) msg-hash)
(puthash "body" (nth 7 l) msg-hash)
(puthash "time" (nth 8 l) msg-hash)
(puthash "unread" (nth 9 l) msg-hash)))
msg-hash))
(defun get-echo-messages (echo)
"Get ECHO messages ordered by time."
(let (msgs)
(setq msgs (make-list 0 (make-hash-table :test 'equal)))
(dolist (l (emacsql (open-echo-db echo)
[:select [id tags author recipient repto echo subj body time unread]
:from messages
:order-by time]))
(if (> (length l) 0)
(setq msgs (append msgs (make-list 1 (make-hash-from-msg-list l))))))
msgs))
(defun get-echo-unread-messages (echo) (defun get-echo-unread-messages (echo)
"Get count of unread messages from ECHO database." "Get count of unread messages from ECHO database."
(car (car (emacsql (open-echo-db echo) (car (car (emacsql (open-echo-db echo)

View File

@ -61,16 +61,25 @@
'("\\<\\(>>?.*\\)\s\\>" . font-lock-comment-face))) '("\\<\\(>>?.*\\)\s\\>" . font-lock-comment-face)))
"Quotes highligting for IDEC mode.") "Quotes highligting for IDEC mode.")
(defvar idec-font-lock-keywords (defvar idec-font-lock-keywords idec-font-lock-keywords-1
'(("function \\(\\sw+\\)" (1 font-lock-function-name-face))) ;; '(("ID" (1 font-lock-function-name-face)))
"Default highlighting expressions for IDEC mode.") "Default highlighting expressions for IDEC mode.")
;; Mode function ;; Mode function
(define-derived-mode idec-mode org-mode "IDEC" (define-generic-mode
'idec
'("//" ">" "ЗЫ" "# ")
'("ii://" "ID" "$subj" "сабж" "субж"
"Subject" "From" "To" "Echo" "At")
'(("=" . 'font-lock-operator)
(";" . 'font-lock-builtin))
'("\\.idec$")
nil)
(define-derived-mode org-idec text-mode "IDEC"
"Major mode for view and editing IDEC messages." "Major mode for view and editing IDEC messages."
:syntax-table idec-mode-syntax-table :syntax-table idec-mode-syntax-table
(setq-local comment-start "// ") (setq-local comment-start "/{2} ")
(setq-local comment-start-skip "//+\\s-*")
(setq-local font-lock-defaults (setq-local font-lock-defaults
'(idec-font-lock-keywords)) '(idec-font-lock-keywords))
(use-local-map idec-mode-map) (use-local-map idec-mode-map)
@ -79,19 +88,19 @@
(setq mode-name "[IDEC]") (setq mode-name "[IDEC]")
(run-hooks 'idec-mode-hook)) (run-hooks 'idec-mode-hook))
;; (defun idec-mode () (defun idec-mode ()
;; "Major mode for view and editing IDEC messages." "Major mode for view and editing IDEC messages."
;; (interactive) (interactive)
;; (kill-all-local-variables) (kill-all-local-variables)
;; ;; Mode definition ;; Mode definition
;; (set-syntax-table idec-mode-syntax-table) (set-syntax-table idec-mode-syntax-table)
;; (use-local-map idec-mode-map) (use-local-map idec-mode-map)
;; ;; (font-lock-add-keywords 'idec-mode '(idec-font-lock-keywords)) ;; (font-lock-add-keywords 'idec-mode '(idec-font-lock-keywords))
;; ;; (set (make-local-variable 'font-lock-defaults) '(idec-font-lock-keywords)) ;; (set (make-local-variable 'font-lock-defaults) '(idec-font-lock-keywords))
;; (setq major-mode 'idec-mode) (setq major-mode 'idec-mode)
;; (setq mode-name "[IDEC]") (setq mode-name "[IDEC]")
;; (setq imenu-generic-expression "*IDEC") (setq imenu-generic-expression "*IDEC")
;; (run-hooks 'idec-mode-hook)) (run-hooks 'idec-mode-hook))
(provide 'idec-mode) (provide 'idec-mode)

View File

@ -52,7 +52,9 @@
(princ (concat "To: " (get-message-field (gethash "content" msg-hash) "recipient") "\n")) (princ (concat "To: " (get-message-field (gethash "content" msg-hash) "recipient") "\n"))
(princ (concat "Echo: " (get-message-field (gethash "content" msg-hash) "echo") "\n")) (princ (concat "Echo: " (get-message-field (gethash "content" msg-hash) "echo") "\n"))
(princ (concat "At: " (get-message-field (gethash "content" msg-hash) "time") "\n")) (princ (concat "At: " (get-message-field (gethash "content" msg-hash) "time") "\n"))
(princ (concat "Subject: " (get-message-field (gethash "content" msg-hash) "subj") "\n")) (let (subj)
(setq subj (concat "Subject: " (get-message-field (gethash "content" msg-hash) "subj")))
(princ (concat subj "\n")))
(princ (concat "__________________________________\n\n" (princ (concat "__________________________________\n\n"
(s-join "\n" (get-message-field (gethash "content" msg-hash) "body")))) (s-join "\n" (get-message-field (gethash "content" msg-hash) "body"))))
(princ "\n__________________________________\n") (princ "\n__________________________________\n")
@ -64,11 +66,11 @@
(princ "]") (princ "]")
(princ "\t [") (princ "\t [")
(insert-button "Answer with quote") (insert-button "Answer with quote")
(princ "]\n\n")) (princ "]\n\n")))
(add-text-properties (point-min) (point) 'read-only))
;; Plain messages hash proccesing ;; Plain messages hash proccesing
(get-messages-content echo-msg-hash)) (get-messages-content echo-msg-hash))
(idec-mode)))) ;; (idec-mode)
(idec))))
(defun load-echo-messages (echo &optional online) (defun load-echo-messages (echo &optional online)
@ -89,20 +91,38 @@
"Parse RAW-LIST from HTTP response." "Parse RAW-LIST from HTTP response."
(with-output-to-temp-buffer (get-buffer-create "*IDEC: list.txt*") (with-output-to-temp-buffer (get-buffer-create "*IDEC: list.txt*")
(switch-to-buffer "*IDEC: list.txt*") (switch-to-buffer "*IDEC: list.txt*")
(dolist (line (split-string (decode-coding-string raw-list 'utf-8) "\n")) (let (len lst)
(when (not (equal line "")) ;; Calculate echo name
;; Defind echo (setq lst (list))
(defvar current-echo nil) (dolist (l (split-string (decode-coding-string raw-list 'utf-8) "\n"))
(setq current-echo (nth 0 (split-string line ":"))) (add-to-list 'lst (nth 0 (split-string l ":")) t))
;; Create clickable button (setq len (get-longest-string lst))
(insert-text-button current-echo (message (concat "Longest echo " (number-to-string len)))
'action (lambda (x) (load-echo-messages (button-get x 'echo) t)) (dolist (line (split-string (decode-coding-string raw-list 'utf-8) "\n"))
'help-echo (concat "Go to echo " current-echo) (when (not (equal line ""))
'echo current-echo) ;; Define echo
(princ (format "\t\t||%s\t\t%s\n" (defvar current-echo nil)
(nth 2 (split-string line ":")) (setq current-echo (nth 0 (split-string line ":")))
(nth 1 (split-string line ":"))))) ;; Create clickable button
)) (insert-text-button current-echo
'action (lambda (x) (load-echo-messages (button-get x 'echo) t))
'help-echo (concat "Go to echo " current-echo)
'echo current-echo)
(save-excursion
(let (s e)
(setq e (point))
(beginning-of-line)
(setq s (point))
(add-text-properties s e '(comment t face '(:foreground "light green")))))
(princ (make-string (+ 3 (- len (length current-echo))) ? ))
(princ (format "%s\n"
(nth 2 (split-string line ":"))))
(save-excursion
(let (s e)
(setq e (point))
(re-search-backward " ")
(setq s (point))
(add-text-properties s e '(comment t face '(:foreground "light blue")))))))))
(idec-mode)) (idec-mode))
(defun idec-fetch-echo-list (nodeurl) (defun idec-fetch-echo-list (nodeurl)

View File

@ -212,7 +212,7 @@ optionaly return cursor to CHECKPOINT."
(setq start (point)) (setq start (point))
(end-of-line) (end-of-line)
(setq end (point)) (setq end (point))
(add-text-properties start end '(comment t face '(:foreground "green"))) (add-text-properties start end '(comment t face '(:foreground "light green")))
(princ (concat (dots echo) (princ (concat (dots echo)
"(" "("
@ -248,7 +248,9 @@ optionaly return cursor to CHECKPOINT."
(interactive) (interactive)
(if (not echo) (if (not echo)
(setq echo (read-string "Enter echo name: "))) (setq echo (read-string "Enter echo name: ")))
(with-output-to-temp-buffer (get-buffer-create (concat "*IDEC: INBOX->(" echo ")") ))) (with-output-to-temp-buffer (get-buffer-create (concat "*IDEC: INBOX->(" echo ")") )
(princ (number-to-string (length (get-echo-messages echo))))
(idec-mode)))
;; END OF LOCAL MAIL FUNCTIONS ;; END OF LOCAL MAIL FUNCTIONS
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -313,8 +315,7 @@ optionaly return cursor to CHECKPOINT."
(princ "]") (princ "]")
(add-text-properties (point-min) (point-max) 'read-only)) (add-text-properties (point-min) (point-max) 'read-only))
(point-max) (point-max)
(idec-mode) (idec-mode))
(visual-line-mode))
(defun display-new-messages () (defun display-new-messages ()
"Display new fetched messages from `new-messages-list'." "Display new fetched messages from `new-messages-list'."