Skip to content

Commit

Permalink
Improvements and addons, text formatting in chatbuf input
Browse files Browse the repository at this point in the history
- [add] Workaround avatar gaps in some chats
  By custom option `telega-avatar-workaround-gaps-for`

- [enh] Use `telega-symbol-mention-mark` only on first line of the
  message header

- [add] Text formatting with `telega-chabuf-input-formatting-set` new
  command, bound to `C-c C-e` by default.

- [refactor] Rename `telega--entity-to-properties` to
  `telega--entity-type-to-text-props` and accept entity type as argument
  instead of entity, because only entity type is used inside this
  function.

Version -> 0.8.215
  • Loading branch information
zevlg committed Nov 17, 2023
1 parent 1b41fe1 commit ce1f226
Show file tree
Hide file tree
Showing 11 changed files with 394 additions and 233 deletions.
11 changes: 5 additions & 6 deletions contrib/telega-url-shorten.el
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,12 @@ chats matching this chat filter."
:ascent center :height ,(telega-chars-xheight 1)
,@props))

(defun telega-url-shorten--e-t-p (old-e-t-p entity text)
(defun telega-url-shorten--e-t-p (old-e-t-p ent-type text)
"Change resulting `telega-display' property by shortening URL."
(let* ((result (funcall old-e-t-p entity text))
(let* ((result (funcall old-e-t-p ent-type text))
(result-td (plist-get result 'telega-display)))
(when (and result-td
(eq 'textEntityTypeUrl
(telega--tl-type (plist-get entity :type))))
(eq 'textEntityTypeUrl (telega--tl-type ent-type)))
(when-let ((pmatch (cdr (cl-find result-td telega-url-shorten-regexps
:test (lambda (res pattern)
(string-match
Expand All @@ -184,9 +183,9 @@ chats matching this chat filter."
"Toggle URLs shortening mode."
:init-value nil :group 'telega-modes
(if telega-url-shorten-mode
(advice-add 'telega--entity-to-properties
(advice-add 'telega--entity-type-to-text-props
:around #'telega-url-shorten--e-t-p)
(advice-remove 'telega--entity-to-properties
(advice-remove 'telega--entity-type-to-text-props
#'telega-url-shorten--e-t-p)))

(defun telega-url-shorten-mode--maybe (&optional arg)
Expand Down
31 changes: 28 additions & 3 deletions etc/langs/en.plist
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Example: 23 y.o. designer from San Francisco")
("lng_polls_solution_title"
:value "Explanation")
("lng_polls_view_results"
:value "View results")
:value "View results")
("lng_deleted"
:value "Deleted Account")
Expand Down Expand Up @@ -1059,7 +1059,7 @@ Telegram offers a free and unlimited service to hundreds of millions of users, w
("lng_media_file_title"
:value "Files")
("lng_media_save_progress"
:value "{ready} of {total} {mb}")
:value "{ready} of {total} {mb}")
;; media types
("lng_in_dlg_photo"
Expand Down Expand Up @@ -1215,7 +1215,7 @@ You can send them an invite link as message instead.")
;; Connected websites
("lng_sessions_browser"
:value "Browser")
:value "Browser")
("lng_settings_connected_title"
:value "Connected websites")
("lng_settings_logged_in_title"
Expand Down Expand Up @@ -1350,4 +1350,29 @@ You can send them an invite link as message instead.")
;; Game
("lng_game_tag"
:value "Game")
("lng_menu_formatting"
:value "Formatting")
("lng_menu_formatting_bold"
:value "Bold")
("lng_menu_formatting_clear"
:value "Clear formatting")
("lng_menu_formatting_italic"
:value "Italic")
("lng_menu_formatting_spoiler"
:value "Spoiler")
("lng_menu_formatting_underline"
:value "Underline")
("lng_menu_formatting_link_edit"
:value "Edit link")
("lng_menu_formatting_monospace"
:value "Monospace")
("lng_menu_formatting_blockquote"
:value "Quote")
("lng_menu_formatting_strike_out"
:value "Strikethrough")
("lng_menu_formatting_link_create"
:value "Create link")
("lng_formatting_link_url"
:value "URL")
)
37 changes: 33 additions & 4 deletions telega-chat.el
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,11 @@ new Chat buffers.")
;; {{{fundoc(telega-chatbuf-attach-clipboard,2)}}}
(define-key map (kbd "C-c C-v") 'telega-chatbuf-attach-clipboard)

;;; ellit-org: chatbuf-attach-bindings
;; - {{{where-is(telega-chabuf-input-formatting-set,telega-chat-mode-map)}}} ::
;; {{{fundoc(telega-chabuf-input-formatting-set,2)}}}
(define-key map (kbd "C-c C-e") #'telega-chabuf-input-formatting-set)

;;; ellit-org: chatbuf-filtering-bindings
;; - {{{where-is(telega-chatbuf-filter,telega-chat-mode-map)}}} ::
;; {{{fundoc(telega-chatbuf-filter,2)}}}
Expand Down Expand Up @@ -3759,14 +3764,38 @@ CALLBACK if non-nil, then called with total number of loaded messages."
(telega-chatbuf--load-history (plist-get (telega-chatbuf--last-msg) :id)
(- 1 telega-chat-history-limit) telega-chat-history-limit))))

(defun telega-chatbuf-cancel-markup (begin end)
"Cancel markup for the given region in the chatbuf input."
(defun telega-chabuf-input-formatting-set (begin end ent-type)
"Attach formatting to the region in the chatbuf input."
(interactive (progn
(unless (region-active-p)
(user-error "Can add formatting to a region only"))
(list (region-beginning) (region-end)
(telega-completing-read-text-formatting-entity
(concat (telega-i18n "lng_menu_formatting") ": ")))))

(unless (and (>= begin telega-chatbuf--input-marker)
(> end telega-chatbuf--input-marker))
(user-error "telega: Can add formatting only inside chatbuf input"))

;; NOTE: nil ent-type mean clear text
(if ent-type
(let* ((props (telega--entity-type-to-text-props
ent-type (buffer-substring-no-properties begin end)))
(tdisp (plist-get props 'telega-display)))
(when tdisp
(plist-put props 'display tdisp))
(set-text-properties begin end props))

(telega-chatbuf-input-formatting-cancel begin end)))

(defun telega-chatbuf-input-formatting-cancel (begin end)
"Cancel formatting for the given region in the chatbuf input."
(interactive (if (region-active-p)
(list (region-beginning) (region-end))
(list telega-chatbuf--input-marker (point-max))))
(unless (and (>= begin telega-chatbuf--input-marker)
(> end telega-chatbuf--input-marker))
(user-error "telega: Can cancel markup only inside chatbuf input"))
(user-error "telega: Can cancel formatting only inside chatbuf input"))
(remove-text-properties begin end '(face nil :tl-entity-type nil)))

(defun telega-chatbuf-cancel-aux (&optional arg)
Expand All @@ -3784,7 +3813,7 @@ Call `telega-chatbuf-cancel-aux' if replying/editing to a message.
Otherwise clear chatbuf input."
(interactive)
(cond ((region-active-p)
(call-interactively #'telega-chatbuf-cancel-markup))
(call-interactively #'telega-chatbuf-input-formatting-cancel))
(telega-chatbuf--aux-plist
(call-interactively #'telega-chatbuf-cancel-aux))
(t
Expand Down
43 changes: 25 additions & 18 deletions telega-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ display the list.")
(defvar telega--accent-colors-available-ids nil
"Accent colors received by `updateAccentColors' event.")

(defun telega--accent-color-id-built-in-p (color-id)
"Return non-nil if accent color denoted by COLOR-ID is built-in."
(< color-id 7))


;;; Shared chat buffer local variables
(defvar telega-chatbuf--chat nil
Expand Down Expand Up @@ -1746,28 +1750,31 @@ Return what BODY returns."
(region-sym (gensym "region")))
`(let* ((,start-sym (point))
(,lwprefix-sym ,prefix)
(,lwprefix-props-sym (list :telega-lwprefix ,lwprefix-sym
'line-prefix ,lwprefix-sym
'wrap-prefix ,lwprefix-sym))
(telega--column-offset (+ telega--column-offset
(string-width ,lwprefix-sym)))
(if ,lwprefix-sym
(string-width ,lwprefix-sym)
0)))
,region-sym)
(prog1
(progn ,@body)
(while (setq ,region-sym (telega--region-by-text-prop
,start-sym 'line-prefix (point)))
(add-text-properties ,start-sym (car ,region-sym)
,lwprefix-props-sym)
(add-text-properties
(car ,region-sym) (cdr ,region-sym)
(list 'line-prefix (concat ,lwprefix-sym
(get-text-property (car ,region-sym)
'line-prefix))
'wrap-prefix (concat ,lwprefix-sym
(get-text-property (car ,region-sym)
'wrap-prefix))))
(setq ,start-sym (cdr ,region-sym)))
(add-text-properties ,start-sym (point) ,lwprefix-props-sym)))))
(when (and ,lwprefix-sym (not (string-empty-p ,lwprefix-sym)))
(let ((,lwprefix-props-sym (list :telega-lwprefix ,lwprefix-sym
'line-prefix ,lwprefix-sym
'wrap-prefix ,lwprefix-sym)))
(while (setq ,region-sym (telega--region-by-text-prop
,start-sym 'line-prefix (point)))
(add-text-properties ,start-sym (car ,region-sym)
,lwprefix-props-sym)
(add-text-properties
(car ,region-sym) (cdr ,region-sym)
(list 'line-prefix (concat ,lwprefix-sym
(get-text-property (car ,region-sym)
'line-prefix))
'wrap-prefix (concat ,lwprefix-sym
(get-text-property (car ,region-sym)
'wrap-prefix))))
(setq ,start-sym (cdr ,region-sym)))
(add-text-properties ,start-sym (point) ,lwprefix-props-sym)))))))

(defmacro telega-ins-prefix (prefix &rest body)
"In case BODY inserted anything then PREFIX is also inserted before BODY."
Expand Down
127 changes: 63 additions & 64 deletions telega-customize.el
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,11 @@ See `telega-avatar--create-image' for more info."
(number :tag "Margin factar")))
:group 'telega)

(defcustom telega-avatar-one-line-in-msg-header nil
"Non-nil to use one line avatar version in the message header.
Workaround avatar gaps."
(defcustom telega-avatar-workaround-gaps-for nil
"Chat temex for chats to enable workaround for gaps in the avatars."
:package-version '(telega . "0.8.215")
:type 'boolean
:type 'chat-temex
:options '((return t))
:group 'telega)

(defcustom telega-avatar-text-compose-chars nil
Expand Down Expand Up @@ -1861,7 +1861,7 @@ Car of the cons cell is the argument to recenter.
In case message is still not fully observable after applying it,
fallback to cdr argument."
:package-version '(telega . "0.8.215")
:type '(cons integer)
:type '(cons integer integer)
:group 'telega-msg)


Expand Down Expand Up @@ -2233,65 +2233,6 @@ If nil, then user's online status is not displayed."
:type 'string
:group 'telega-symbol)

(when (fboundp 'define-fringe-bitmap)
(define-fringe-bitmap 'telega-mark
(vector #b11111111) nil nil '(top periodic)))

(defcustom telega-symbol-mark
(propertize " " 'face 'custom-invalid)
"*Symbol used to denote marked messages/chats."
:package-version '(telega . "0.8.213")
:type 'string
:group 'telega-symbol)

(when (fboundp 'define-fringe-bitmap)
(define-fringe-bitmap 'telega-mention
(vector #b01111110
#b01111110
#b11000011
#b11000011
#b11001111
#b10011111
#b10110011
#b10110011
#b10011111
#b11001110
#b11000000
#b11000001
#b01111111
#b01111110))

(define-fringe-bitmap 'telega-reaction
(vector #b011000110
#b111101111
#b111111111
#b111111111
#b011111110
#b011111110
#b001111100
#b001111100
#b000111000
#b000111000
#b000010000
)))

(defcustom telega-symbol-mention-mark
(propertize "@" 'face 'telega-mention-count)
"*Symbol used to denote massages which contains unread mention."
:package-version '(telega . "0.8.213")
:type 'string
:group 'telega-symbol)

(defcustom telega-symbol-reaction-mark
(if (fboundp 'define-fringe-bitmap)
(propertize "\u200B" 'display
'(left-fringe telega-reaction telega-mention-count))
(propertize "\u200B" 'face 'telega-mention-count))
"*Symbol used to denote massages which contains unread reaction."
:package-version '(telega . "0.8.13")
:type 'string
:group 'telega-symbol)

(defcustom telega-symbol-alarm "⏲️"
"*Symbol used for scheduled messages."
:type 'string
Expand Down Expand Up @@ -2447,6 +2388,62 @@ Used in one line message inserter."
:type 'string
:group 'telega-symbol)

;; Symbols marking messages of some sort
(when (fboundp 'define-fringe-bitmap)
(define-fringe-bitmap 'telega-mark
(vector #b11111111) nil nil '(top periodic)))

(defcustom telega-symbol-mark
(propertize " " 'face 'custom-invalid)
"*Symbol used to denote marked messages/chats."
:package-version '(telega . "0.8.213")
:type 'string
:group 'telega-symbol)

(when (fboundp 'define-fringe-bitmap)
(define-fringe-bitmap 'telega-mention
(vector #b01111110
#b01111110
#b11000011
#b11000011
#b11001111
#b10011111
#b10110011
#b10110011
#b10011111
#b11001110
#b11000000
#b11000001
#b01111111
#b01111110))

(define-fringe-bitmap 'telega-reaction
(vector #b011000110
#b111101111
#b111111111
#b111111111
#b011111110
#b011111110
#b001111100
#b001111100
#b000111000
#b000111000
#b000010000
)))

(defcustom telega-symbol-mention-mark
(propertize "@" 'face 'telega-mention-count)
"*Symbol used to mark messages which contains unread mention."
:package-version '(telega . "0.8.213")
:type 'string
:group 'telega-symbol)

(defcustom telega-symbol-reaction-mark telega-symbol-reaction
"*Symbol used to mark messages which contains unread reaction."
:package-version '(telega . "0.8.13")
:type 'string
:group 'telega-symbol)

(defcustom telega-symbols-emojify
'((verified (when (and telega-use-images (image-type-available-p 'svg))
(telega-etc-file-create-image "verified.svg" 2)))
Expand Down Expand Up @@ -2487,6 +2484,8 @@ Used in one line message inserter."
(telega-etc-file-create-image "symbols/premium.svg" 2)))
(reaction (when (and telega-use-images (image-type-available-p 'svg))
(telega-etc-file-create-image "symbols/reaction.svg" 2)))
(reaction-mark (when (and telega-use-images (image-type-available-p 'svg))
(telega-etc-file-create-image "symbols/reaction.svg" 2)))
(reply (when (and telega-use-images (image-type-available-p 'svg))
(telega-etc-file-create-image "symbols/reply.svg" 2)))
(reply-quote (when (and telega-use-images (image-type-available-p 'svg))
Expand Down
Loading

0 comments on commit ce1f226

Please sign in to comment.