Function: ConTeXt-find-indent

ConTeXt-find-indent is a byte-compiled function defined in context.el.

Signature

(ConTeXt-find-indent &optional VIRTUAL)

Documentation

Find the proper indentation of text after point.

VIRTUAL if non-nil indicates that we're only trying to find the indentation in order to determine the indentation of something else. There might be text before point.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/context.el
(defun ConTeXt-find-indent (&optional virtual)
  "Find the proper indentation of text after point.
VIRTUAL if non-nil indicates that we're only trying to find the
indentation in order to determine the indentation of something
else.  There might be text before point."
  (save-excursion
    (skip-chars-forward " \t")
    (or
     ;; Trust the current indentation, if such info is applicable.
     (and virtual (>= (current-indentation) (current-column))
          (current-indentation))
     ;; Put leading close-paren where the matching open brace would be.
     (condition-case nil
         (and (eq (char-syntax (char-after)) ?\))
              (save-excursion
                (skip-syntax-forward " )")
                (backward-sexp 1)
                (ConTeXt-find-indent 'virtual)))
       (error nil))
     ;; Default (maybe an argument)
     (let ((pos (point))
           (char (char-after))
           (indent 0)
           up-list-pos)
       ;; Look for macros to be outdented
       (cond ((looking-at (concat (regexp-quote TeX-esc)
                                  (ConTeXt-environment-stop-name)))
              (setq indent (- indent ConTeXt-indent-basic)))
             ((looking-at ConTeXt-indent-item-re)
              (setq indent (- indent ConTeXt-indent-item))))
       ;; Find the previous point which determines our current indentation.
       (condition-case err
           (progn
             (backward-sexp 1)
             (while (or (> (current-column) (current-indentation))
                        ;; Continue going back if we are
                        ;; at a hanging optional group.
                        (looking-at (regexp-quote ConTeXt-optop)))
               (backward-sexp 1)))
         (scan-error
          (setq up-list-pos (nth 2 err))))
       (cond
        ((= (point-min) pos) 0)  ; We're really just indenting the first line.
        ((integerp up-list-pos)
         ;; Have to indent relative to the open-paren.
         (goto-char up-list-pos)
         (if (and (not ConTeXt-indent-allhanging)
                  (> pos (progn (down-list 1)
                                (forward-comment (point-max))
                                (point))))
             ;; Align with the first element after the open-paren.
             (current-column)
           ;; We're the first element after a hanging brace.
           (goto-char up-list-pos)
           (+ indent ConTeXt-indent-basic (ConTeXt-find-indent 'virtual))))
        ;; We're now at the "beginning" of a line.
        ((not (and (not virtual) (eq (char-after) ?\\)))
         ;; Nothing particular here: just keep the same indentation.
         (+ indent (current-column)))
        ;; We're now looking at an item.
        ((looking-at ConTeXt-indent-item-re)
         ;; Indenting relative to an item, have to re-add the outdenting.
         (+ indent (current-column) ConTeXt-indent-item))
        ;; We're looking at an environment starter.
        ((and (looking-at (concat (regexp-quote TeX-esc)
                                  (ConTeXt-environment-start-name)))
              (not (looking-at (concat (regexp-quote TeX-esc)
                                       (ConTeXt-environment-start-name)
                                       ConTeXt-text)))) ; other environments?
         (+ indent (current-column) ConTeXt-indent-basic))
        (t
         (let ((col (current-column)))
           (if (not (and char (eq (char-syntax char) ?\()))
               ;; If the first char was not an open-paren, there's
               ;; a risk that this is really not an argument to the
               ;; macro at all.
               (+ indent col)
             (forward-sexp 1)
             (if (< (line-end-position)
                    (save-excursion (forward-comment (point-max))
                                    (point)))
                 ;; we're indenting the first argument.
                 (min (current-column) (+ ConTeXt-indent-arg col))
               (skip-syntax-forward " ")
               (current-column))))))))))