8

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?

2 Answers 2

1

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).

0

I think the feature you want does not exist yet. Further I think the answer of Anders Johansson is great.

This is a slightly different ansatz and only a start using the org element api:

(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")))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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