* 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-map
(let ((map (make-keymap)))
(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)
(let ((map (make-sparse-keymap)))
(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)
map)
"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
(list
'("\\(ID:.*\\)" . font-lock-function-name-face)
@ -54,30 +61,38 @@
'("\\<\\(>>?.*\\)\s\\>" . font-lock-comment-face)))
"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.")
(defvar idec-mode-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?_ "w" st)
(modify-syntax-entry ?/ ". 2b" st)
st))
;; Mode function
(defun idec-mode ()
(define-derived-mode idec-mode org-mode "IDEC"
"Major mode for view and editing IDEC messages."
(interactive)
(kill-all-local-variables)
;; Mode definition
(set-syntax-table idec-mode-syntax-table)
:syntax-table idec-mode-syntax-table
(setq-local comment-start "// ")
(setq-local comment-start-skip "//+\\s-*")
(setq-local font-lock-defaults
'(idec-font-lock-keywords))
(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-local indent-line-function 'org-indent-line)
(setq imenu-generic-expression "*IDEC")
(setq mode-name "[IDEC]")
(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)
;;; idec-mode.el ends here

View File

@ -64,11 +64,11 @@
(princ "]")
(princ "\t [")
(insert-button "Answer with quote")
(princ "]\n\n")))
(princ "]\n\n"))
(add-text-properties (point-min) (point) 'read-only))
;; Plain messages hash proccesing
(get-messages-content echo-msg-hash))
(idec-mode)))
(add-text-properties (point-min) (point-max) 'read-only))
(idec-mode))))
(defun load-echo-messages (echo &optional online)

29
idec.el
View File

@ -177,10 +177,11 @@ Default to `idec-download-offset'"
3)
? ))
(defun mark-all-as-read (echo)
"Mark all messages in ECHO as read."
(defun mark-all-as-read (echo &optional checkpoint)
"Mark all messages in ECHO as read;
put cursor to CHECKPOINT."
(mark-all-messages-as-read echo)
(idec-local-browse))
(idec-local-browse checkpoint))
(defun idec-mark-all-as-read (&optional echo)
"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 echo)))
(defun idec-local-browse ()
"Browse local mail from `idec-mail-dir'."
(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*")
@ -220,6 +222,7 @@ Default to `idec-download-offset'"
(setq unread (get-echo-unread-messages echo))
(when (> unread 0)
(princ "*"))
(princ " ")
;; [New message] button
(princ "\t[")
@ -229,12 +232,15 @@ Default to `idec-download-offset'"
(princ "]\t[")
;; [Mark read] button
(insert-button "Mark read"
'action (lambda (x) (mark-all-as-read (button-get x 'echo)))
'echo echo)
'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))
(defun browse-local-echo (&optional echo)
@ -242,7 +248,7 @@ Default to `idec-download-offset'"
(interactive)
(if (not echo)
(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
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -258,7 +264,7 @@ Default to `idec-download-offset'"
(if (string-match "\\." line)
(and (setq current-echo 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)
(check-message-in-db line current-echo))
(when (not (string= "" line))
@ -307,7 +313,8 @@ Default to `idec-download-offset'"
(princ "]")
(add-text-properties (point-min) (point-max) 'read-only))
(point-max)
(idec-mode))
(idec-mode)
(visual-line-mode))
(defun display-new-messages ()
"Display new fetched messages from `new-messages-list'."
@ -382,7 +389,7 @@ Default to `idec-download-offset'"
nil
(maphash (lambda (id msg)
(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))
(get-messages-content ids))))