Index: sbbs.el ================================================================== --- sbbs.el +++ sbbs.el @@ -486,10 +486,54 @@ (setq header-line-format (format "Responding to Thread %d" id) sbbs--thread-id id sbbs--board board) (switch-to-buffer (current-buffer))))) +(defun sbbs-compose-format (style) + "Insert " + (if (region-active-p) + (save-excursion + (goto-char (region-beginning)) + (insert "style") + (goto-char (region-end)) + (insert "style")) + (insert style style) + (forward-char (- (length style))))) + +(defun sbbs-compose-format-code () + "Insert code syntax markers." + (interactive) + (sbbs-compose-format "```\n")) + +(defun sbbs-compose-format-bold () + "Insert bold syntax markers." + (interactive) + (sbbs-compose-format "**")) + +(defun sbbs-compose-format-italic () + "Insert italic syntax markers." + (interactive) + (sbbs-compose-format "__")) + +(defun sbbs-compose-format-verbatim () + "Insert verbatim syntax markers." + (interactive) + (sbbs-compose-format "==")) + +(defun sbbs-compose-format-spoiler () + "Insert spoiler syntax markers." + (interactive) + (sbbs-compose-format "~~")) + +(defun sbbs-compose-unformat () + (interactive) + (when (search-backward-regexp "\\(\\*\\*\\|==\\|__\\|~~\\)" nil t) + (looking-at (concat "\\(" (regexp-quote (match-string 1)) "\\).*?" + "\\(" (regexp-quote (match-string 1)) "\\)")) + (replace-match "" nil nil nil 2) + (replace-match "" nil nil nil 1))) + (defun sbbs-compose-create () "Upload response or thread to board." (interactive) (let ((board sbbs--board) (url-request-method "POST") @@ -603,10 +647,16 @@ (add-hook 'post-command-hook #'sbbs--uncover-spoiler nil t)) (defvar sbbs-compose-mode-map (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-c C-f C-b") #'sbbs-compose-format-bold) + (define-key map (kbd "C-c C-f C-i") #'sbbs-compose-format-italic) + (define-key map (kbd "C-c C-f C-v") #'sbbs-compose-format-verbatim) + (define-key map (kbd "C-c C-f C-s") #'sbbs-compose-format-spoiler) + (define-key map (kbd "C-c C-f C-c") #'sbbs-compose-format-code) + (define-key map (kbd "C-c C-f C-d") #'sbbs-compose-unformat) (define-key map (kbd "C-c C-c") #'sbbs-compose-create) map)) (defvar sbbs--font-lock ;; stolen/based on from http://textboard.org/prog/81/5