Function: lua-make-indentation-info-pair

lua-make-indentation-info-pair is a byte-compiled function defined in lua-mode.el.gz.

Signature

(lua-make-indentation-info-pair FOUND-TOKEN FOUND-POS)

Documentation

Create a pair from FOUND-TOKEN and FOUND-POS for indentation calculation.

This is a helper function to lua-calculate-indentation-info. Don't use standalone.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/lua-mode.el.gz
(defun lua-make-indentation-info-pair (found-token found-pos)
  "Create a pair from FOUND-TOKEN and FOUND-POS for indentation calculation.

This is a helper function to `lua-calculate-indentation-info'.
Don't use standalone."
  (cond
   ;; Functions are a bit tricky to indent right.  They can appear in a
   ;; lot ot different contexts.  Until I find a shortcut, I'll leave it
   ;; with a simple relative indentation.
   ;; The special cases are for indenting according to the location of
   ;; the function. i.e.:
   ;;     (cons 'absolute (+ (current-column) lua-indent-level))
   ;; TODO: Fix this.  It causes really ugly indentations for in-line
   ;; functions.
   ((string-equal found-token "function")
    (cons 'relative lua-indent-level))

   ;; Block openers
   ((and lua-indent-nested-block-content-align
         (member found-token (list "{" "(" "[")))
    (save-excursion
      (let ((found-bol (line-beginning-position)))
        (forward-comment (point-max))
        ;; If the next token is on this line and it's not a block
        ;; opener, the next line should align to that token.
        (if (and (zerop (count-lines found-bol (line-beginning-position)))
                 (not (looking-at lua-indentation-modifier-regexp)))
            (cons 'absolute (current-column))
          (cons 'relative lua-indent-level)))))

   ;; These are not really block starters.  They should not add to
   ;; indentation.  The corresponding "then" and "do" handle the
   ;; indentation.
   ((member found-token (list "if" "for" "while"))
    (cons 'relative 0))
   ;; closing tokens follow: These are usually taken care of by
   ;; lua-calculate-indentation-override.
   ;; elseif is a bit of a hack. It is not handled separately, but it
   ;; needs to nullify a previous then if on the same line.
   ((member found-token (list "until" "elseif"))
    (save-excursion
      (let* ((line-beginning (line-beginning-position))
             (same-line (and (lua-goto-matching-block-token found-pos 'backward)
                             (<= line-beginning (point)))))
        (if same-line
            (cons 'remove-matching 0)
          (cons 'relative 0)))))

   ;; else is a special case; if its matching block token is on the same
   ;; line, instead of removing the matching token, it has to replace
   ;; it, so that either the next line will be indented correctly, or
   ;; the end on the same line will remove the effect of the else.
   ((string-equal found-token "else")
    (save-excursion
      (let* ((line-beginning (line-beginning-position))
             (same-line (and (lua-goto-matching-block-token found-pos 'backward)
                             (<= line-beginning (point)))))
        (if same-line
            (cons 'replace-matching (cons 'relative lua-indent-level))
          (cons 'relative lua-indent-level)))))

   ;; Block closers.  If they are on the same line as their openers,
   ;; they simply eat up the matching indentation modifier.  Otherwise,
   ;; they pull indentation back to the matching block opener.
   ((member found-token (list ")" "}" "]" "end"))
    (save-excursion
      (let* ((line-beginning (line-beginning-position))
             (same-line (and (lua-goto-matching-block-token found-pos 'backward)
                             (<= line-beginning (point))))
             (opener-pos (point))
             opener-continuation-offset)
        (if same-line
            (cons 'remove-matching 0)
          (back-to-indentation)
          (setq opener-continuation-offset
                (if (lua-is-continuing-statement-p-1) lua-indent-level 0))

          ;; Accumulate indentation up to opener, including indentation.
          ;; If there were no other indentation modifiers until said
          ;; opener, ensure there is no continuation after the closer.
          `(multiple . ((absolute . ,(- (current-indentation)
                                        opener-continuation-offset))
                        ,@(when (/= opener-continuation-offset 0)
                            (list (cons 'continued-line
                                        opener-continuation-offset)))
                        ,@(delete nil (list (lua-calculate-indentation-info-1
                                             nil opener-pos)))
                        (cancel-continued-line . nil)))))))

   ((member found-token '("do" "then"))
    `(multiple . ((cancel-continued-line . nil) (relative . ,lua-indent-level))))

   ;; Everything else.  This is from the original code: If opening a
   ;; block (match-data 1 exists), then push indentation one level up,
   ;; if it is closing a block, pull it one level down.
   ('other-indentation-modifier
    (cons 'relative (if (nth 2 (match-data))
                        ;; Beginning of a block matched
                        lua-indent-level
                      ;; End of a block matched
                      (- lua-indent-level))))))