makefile 모드에서 들여 쓰기를 사용자 정의 하시겠습니까?


11

내 makefile에서 연속 줄에 대해 다음 들여 쓰기를 선호합니다.

FILES:=                \
    file1.cpp          \
    file2.cpp          \
    fileYetAnother.cpp

LIBS:=                 \
    libsth1.so         \
    libelsewhere.so

여전히 makefile 모드는 다음과 같은 방식으로 들여 쓰기합니다 (파일 또는 영역을 다시 들여 쓸 것인지 물을 때).

FILES:=            \
file1.cpp          \
file2.cpp          \
fileYetAnother.cpp

LIBS:=             \
libsth1.so         \
libelsewhere.so

어떻게 든 이전 변형을 사용하도록 구성 할 수 있습니까 (= 4 줄이나 탭으로 연속 줄 들여 쓰기)?


무엇에 대한 indent-according-to-mode명령?
— Andriy Tykhonov

답변:


1

purple_arrows '솔루션 구축 :

(defun my-makefile-indent-line ()
  (save-excursion
(forward-line 0)
(cond
 ;; keep TABs
 ((looking-at "\t")
  t)
 ;; indent continuation lines to 4
 ((and (not (bobp))
       (= (char-before (1- (point))) ?\\))
  (delete-horizontal-space)
  (indent-to 4))
 ;; delete all other leading whitespace
 ((looking-at "\\s-+")
  (replace-match "")))))

(add-hook 'makefile-mode-hook
      (lambda ()
    (setq-local indent-line-function 'my-makefile-indent-line)))

유일한 문제는 내 코드가 변경되지 않기 때문에 TAB이 파일 목록을 들여 쓰기하면 이것이 작동하지 않는다는 것입니다.
— Alex Schröder

들여 쓰기를 4로 수정하는 것은 좋은 해결책이 아닙니다. FILES그리고 and LIBS가 길고 뒤에 하나의 요소가 있으면 :=다음 요소를 첫 번째 요소와 더 잘 정렬하십시오 :=.
— CodyChan

이 질문에 네 개의 공백이 있습니다.
— Alex Schröder

0

예. 어떻게 든 구성 할 수 있습니다.

(스낵에 대한 사과와 함께)

들여 쓰기 라인 당신이 원하는대로, 다음 설정하는 함수를 작성하는 변수의 값과 기능 indent-line-function에 대한 makefile-mode. 다음과 같은 것 :

(defun my-makefile-indent-line ()
  ...)

(add-hook 'makefile-mode-hook (lambda () (setq-local indent-line-function 'my-makefile-indent-line)))

글쎄, 그 3 점은 sth입니다. 채우는 방법을 모르겠습니다 ... 그러나 부분 포인터에 감사드립니다.
— Mekk

0

를 사용하는 경우 다음 목록에 aggressive-indent-mode도움이되었습니다 .makefile-modeaggressive-indent-excluded-modes

(global-aggressive-indent-mode)
(add-to-list 'aggressive-indent-excluded-modes 'makefile-mode)

이 기능은 global-aggressive-indent-mode켜져있는 상태 에서만 작동 합니다.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.