* idec-mode parent is org-mode

* save cursor position in `idec-local-browse'

* some consmetic
This commit is contained in:
Denis Zheleztsov 2017-10-20 13:52:38 +03:00
parent 72b771d11e
commit a208a5192a
3 changed files with 56 additions and 34 deletions

View File

@ -36,13 +36,20 @@
(defvar idec-mode-hook nil) (defvar idec-mode-hook nil)
(defvar idec-mode-map (defvar idec-mode-map
(let ((map (make-keymap))) (let ((map (make-sparse-keymap)))
(define-key map "\C-c \C-c" 'kill-this-buffer) (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-n"] 'idec-next-message)
(define-key map "\C-c \C-b" 'idec-previous-message) (define-key map ["C-c C-b"] 'idec-previous-message)
(define-key map ["C-c C-e"] 'idec-new-message)
map) map)
"Keymapping for IDEC mode.") "Keymapping for IDEC mode.")
(defvar idec-mode-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?# "<" st)
(modify-syntax-entry ?\n ">" st)
st))
(defconst idec-font-lock-keywords-1 (defconst idec-font-lock-keywords-1
(list (list
'("\\(ID:.*\\)" . font-lock-function-name-face) '("\\(ID:.*\\)" . font-lock-function-name-face)
@ -54,30 +61,38 @@
'("\\<\\(>>?.*\\)\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 idec-font-lock-keywords-2 (defvar idec-font-lock-keywords
'(("function \\(\\sw+\\)" (1 font-lock-function-name-face)))
"Default highlighting expressions for IDEC mode.") "Default highlighting expressions for IDEC mode.")
(defvar idec-mode-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?_ "w" st)
(modify-syntax-entry ?/ ". 2b" st)
st))
;; Mode function ;; Mode function
(defun idec-mode () (define-derived-mode idec-mode org-mode "IDEC"
"Major mode for view and editing IDEC messages." "Major mode for view and editing IDEC messages."
(interactive) :syntax-table idec-mode-syntax-table
(kill-all-local-variables) (setq-local comment-start "// ")
;; Mode definition (setq-local comment-start-skip "//+\\s-*")
(set-syntax-table idec-mode-syntax-table) (setq-local font-lock-defaults
'(idec-font-lock-keywords))
(use-local-map idec-mode-map) (use-local-map idec-mode-map)
;; (font-lock-add-keywords 'idec-mode '(idec-font-lock-keywords)) (setq-local indent-line-function 'org-indent-line)
;; (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") (setq imenu-generic-expression "*IDEC")
(setq mode-name "[IDEC]")
(run-hooks 'idec-mode-hook)) (run-hooks 'idec-mode-hook))
;; (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))
(provide 'idec-mode) (provide 'idec-mode)
;;; idec-mode.el ends here ;;; idec-mode.el ends here

View File

@ -64,11 +64,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))))
(add-text-properties (point-min) (point-max) 'read-only))
(defun load-echo-messages (echo &optional online) (defun load-echo-messages (echo &optional online)

29
idec.el
View File

@ -177,10 +177,11 @@ Default to `idec-download-offset'"
3) 3)
? )) ? ))
(defun mark-all-as-read (echo) (defun mark-all-as-read (echo &optional checkpoint)
"Mark all messages in ECHO as read." "Mark all messages in ECHO as read;
put cursor to CHECKPOINT."
(mark-all-messages-as-read echo) (mark-all-messages-as-read echo)
(idec-local-browse)) (idec-local-browse checkpoint))
(defun idec-mark-all-as-read (&optional echo) (defun idec-mark-all-as-read (&optional echo)
"Mark all messages in ECHO as read." "Mark all messages in ECHO as read."
@ -189,8 +190,9 @@ Default to `idec-download-offset'"
(mark-all-messages-as-read (read-string "Enter echo name: ")) (mark-all-messages-as-read (read-string "Enter echo name: "))
(mark-all-messages-as-read echo))) (mark-all-messages-as-read echo)))
(defun idec-local-browse () (defun idec-local-browse (&optional checkpoint)
"Browse local mail from `idec-mail-dir'." "Browse local mail from `idec-mail-dir';
optionaly return cursor to CHECKPOINT."
(interactive) (interactive)
(get-buffer-create "*IDEC: INBOX*") (get-buffer-create "*IDEC: INBOX*")
(with-output-to-temp-buffer (get-buffer-create "*IDEC: INBOX*") (with-output-to-temp-buffer (get-buffer-create "*IDEC: INBOX*")
@ -220,6 +222,7 @@ Default to `idec-download-offset'"
(setq unread (get-echo-unread-messages echo)) (setq unread (get-echo-unread-messages echo))
(when (> unread 0) (when (> unread 0)
(princ "*")) (princ "*"))
(princ " ")
;; [New message] button ;; [New message] button
(princ "\t[") (princ "\t[")
@ -229,12 +232,15 @@ Default to `idec-download-offset'"
(princ "]\t[") (princ "]\t[")
;; [Mark read] button ;; [Mark read] button
(insert-button "Mark read" (insert-button "Mark read"
'action (lambda (x) (mark-all-as-read (button-get x 'echo))) 'action (lambda (x) (mark-all-as-read (button-get x 'echo) (button-get x 'point)))
'echo echo) 'echo echo
'point (point))
(princ "]\n")) (princ "]\n"))
(message (concat "IDEC: FUUUUUU <" echo ">"))) (message (concat "IDEC: FUUUUUU <" echo ">")))
)) ))
(add-text-properties (point-min) (point-max) 'read-only)) (add-text-properties (point-min) (point-max) 'read-only))
(if checkpoint
(goto-char checkpoint))
(idec-mode)) (idec-mode))
(defun browse-local-echo (&optional echo) (defun browse-local-echo (&optional echo)
@ -242,7 +248,7 @@ Default to `idec-download-offset'"
(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->(" ) ))) (with-output-to-temp-buffer (get-buffer-create (concat "*IDEC: INBOX->(" echo ")") )))
;; END OF LOCAL MAIL FUNCTIONS ;; END OF LOCAL MAIL FUNCTIONS
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -258,7 +264,7 @@ Default to `idec-download-offset'"
(if (string-match "\\." line) (if (string-match "\\." line)
(and (setq current-echo line) (and (setq current-echo line)
(store-echo-counter line)) (store-echo-counter line))
(when (and (check-message-in-echo line current-echo) (when (and ;; (check-message-in-echo line current-echo)
(> (length line) 1) (> (length line) 1)
(check-message-in-db line current-echo)) (check-message-in-db line current-echo))
(when (not (string= "" line)) (when (not (string= "" line))
@ -307,7 +313,8 @@ Default to `idec-download-offset'"
(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'."
@ -382,7 +389,7 @@ Default to `idec-download-offset'"
nil nil
(maphash (lambda (id msg) (maphash (lambda (id msg)
(insert-message-to-db (gethash "content" msg) id) (insert-message-to-db (gethash "content" msg) id)
(store-message (gethash "content" msg) (gethash "echo" msg) id) ;; (store-message (gethash "content" msg) (gethash "echo" msg) id)
(puthash id (gethash "content" msg) new-messages-list)) (puthash id (gethash "content" msg) new-messages-list))
(get-messages-content ids)))) (get-messages-content ids))))