patternMinor
Minor mode for blog writing in HTML
Viewed 0 times
minormodewritingforbloghtml
Problem
This is a collection of reasonably useful functions I put together for writing my blog.
``
(interactive)
(insert-tag ,start-tag ,end-tag)))
(defmacro defregion (tag-name start-tag end-tag)
"Defines region wrapper function."
`(defun ,(make-symbol (concat "region-to-" (symbol-name tag-name))) ()
(interactive)
(wrap-region (region-beginning) (region-end) ,start-tag ,e
``
(require 'htmlize)
(defvar blog-mode-map nil
"Keymap for blog minor mode")
(unless blog-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-cl" 'insert-link)
(define-key map "\C-cp" 'insert-code-block)
(define-key map "\C-cc" 'insert-inline-code)
(define-key map "\C-cb" 'insert-bold)
(define-key map "\C-cq" 'insert-quote)
(define-key map "\C-cs" 'insert-sig)
(define-key map "\C-cf" 'insert-footnote)
(define-key map "\C-c\C-l" 'region-to-link)
(define-key map "\C-c\C-p" 'region-to-code-block)
(define-key map "\C-c\C-c" 'region-to-inline-code)
(define-key map "\C-c\C-b" 'region-to-bold)
(define-key map "\C-c\C-q" 'region-to-quote)
(define-key map "\C-c\C-s" 'region-to-sig)
(define-key map "\C-c\C-f" 'region-to-footnote)
(define-key map "/" 'smart-backslash)
(setq blog-mode-map map)))
(define-minor-mode blog-mode
"This is a collection of useful keyboard macros for editing Langnostic"
nil
" Blog"
(use-local-map blog-mode-map))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; simple definitions
(defun insert-tag (start-tag &optional end-tag)
"Inserts a tag at point"
(interactive)
(insert start-tag)
(save-excursion
(insert (or end-tag ""))))
(defun wrap-region (start end start-tag &optional end-tag)
"Inserts end tag at the end of the region, and start tag at point"
(goto-char end)
(insert (or end-tag ""))
(goto-char start)
(insert start-tag))
(defmacro definsert (tag-name start-tag end-tag)
"Defines insert function."
(defun ,(make-symbol (concat "insert-" (symbol-name tag-name))) ()(interactive)
(insert-tag ,start-tag ,end-tag)))
(defmacro defregion (tag-name start-tag end-tag)
"Defines region wrapper function."
`(defun ,(make-symbol (concat "region-to-" (symbol-name tag-name))) ()
(interactive)
(wrap-region (region-beginning) (region-end) ,start-tag ,e
Solution
Not sure if this is relevant as it is a year old but, you can look at https://github.com/Neil-Smithline/defassoclist to see how to create multiple functions in a macro.
You didn't include your failed attempts with
You didn't include your failed attempts with
progn so I can't tell you what you were doing wrong but progn does work.Context
StackExchange Code Review Q#1467, answer score: 3
Revisions (0)
No revisions yet.