7

Can indentation of the Org mode quote block be configured? I would like to highlight quote blocks with indented margins, both left and right if possible:

enter image description here

The example above demonstrates org-quote face properties (e.g.: :height :foreground, etc.) modified in my theme. However the left and right margins shown in the quote block are faked using spaces. Perhaps indentation is set by wrap-prefix, which is a special text property? If this is the right direction, how could I set a custom wrap-prefix for org-quote blocks only?

0

I think the feature you want does not exist yet.

For a start you can use a function to set the text property line-prefix for quote blocks.

(defun mw-org-left-margin-for-quote-blocks ()
"Insert a tab as left margin for every org quote block."
(interactive)
(let ((data (org-element-parse-buffer)))
    (org-element-map data 'quote-block
      (lambda (ele)
        (put-text-property
         (save-excursion
           (goto-char (org-element-property :begin ele))
           (beginning-of-line 2)
           (point))
         (save-excursion
           (goto-char (org-element-property :end ele))
           (end-of-line -1)
           (point))
         'line-prefix "\t")))))
0

It can be done quite easily during font-lock by adding a custom function to org-font-lock-hook. This works well unless you use org-indent-mode, which recalculates and overrides line-prefix and wrap-prefix after buffer changes.

(add-hook 'org-font-lock-hook #'aj/org-indent-quotes)

(defun aj/org-indent-quotes (limit)
  (let ((case-fold-search t))
    (while (search-forward-regexp "^[ \t]*#\\+begin_quote" limit t)
      (let ((beg (1+ (match-end 0))))
        ;; on purpose, we look further than LIMIT
        (when (search-forward-regexp "^[ \t]*#\\+end_quote" nil t)
          (let ((end (1- (match-beginning 0)))
                (indent (propertize "    " 'face 'org-hide)))
            (add-text-properties beg end (list 'line-prefix indent
                                               'wrap-prefix indent))))))))

I don’t think there is an easy way of making it wrap earlier at the end of line, i.e. right indent (there is no “wrap-suffix” property).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.