Programing

Xcode에서 후행 공백 제거

lottogame 2020. 8. 29. 11:47
반응형

Xcode에서 후행 공백 제거


파일을 저장할 때 Xcode가 후행 공백을 제거하도록 강제하는 방법이 있습니까?

중요한 경우 3.1.3 버전을 사용하고 있습니다.


스크립트를 생성하고 키보드 단축키에 바인딩 할 수 있습니다.

  • 스크립트 메뉴> 사용자 스크립트 편집 ...을 선택합니다 .
  • + 버튼을 누르고 새 셸 스크립트를 선택 합니다.
  • "Strip Trailing Spaces"와 같은 이름을 지정하고 ⌃⇧R과 같은 바로 가기를 지정합니다.
  • 입력을 "선택"으로 설정하고 출력을 "선택 대체"로 설정합니다.

그런 다음 다음 스크립트를 입력하십시오.

#!/usr/bin/perl

while (<>) {
    s/\s+$//;
    print "$_\n";
}

Xcode 4.4부터 공백은 줄이 모두 공백이 아닌 한 기본적으로 자동으로 잘립니다. Including whitespace-only lines이 문제를 해결하기 위해 활성화 할 수도 있으며 이는 기본적으로 활성화되지 않습니다.

이동 Xcode > Preferences > Text Editing > While editing

Xcode 환경 설정 스크린 샷


I'm using the Google Toolbox For Mac Xcode Plugin, it adds a "Correct whitespace on save" parameter that trim trailing whitespace on save. I missed that a lot from emacs.


For Xcode 8, I installed the swimat Xcode plug-in, for formatting Swift code, which removed all trailing spaces and whitespace-only lines.

Installation Methods

  1. Install via homebrew-cask:

    brew cask install swimat
    
  2. Download the App directly:
    https://github.com/Jintin/Swimat/releases/download/v1.3.5/Swimat.zip

  3. Clone extension branch and archive to Mac App.

Usage

Once installed, you can run Swimat in Xcode via Editor -> Swimat -> Format.


This is not possible in Xcode 3.2

Edit:

I answered this question so briefly because there's no way to do this properly.

Of course, since it's software, you can do anything: Starting with Input Manager hacks or other ways of code injection to system wide keyboard interception, you can alter your local system to do anything anytime. You could set up an Applescript folder action (arrgh) or use a launch demon and the FSEvents facility to watch your source code files.

You can also add a couple of scripts to Xcode (user scripts in the menu, script phases in targets, custom Actions in the organizer, there's even the very unknown possibility a startup script), but all these solutions are flawed, since it involves the user or custom setup on the user's machine.

I'm not aware of a solution which simply works after checking out a project from SCM. I believe that there's need for this and similar customization scripts, so I filed a bug (radar 7203835, "Feature: more user script triggers in Xcode workflow"). I did not receive any feedback yet.

Here's the full text of the radar entry:

It would be useful to have more places to run scripts in Xcode.

Examples:

  1. Pre build scripts
    Pre build scripts could be used to build prerequisites like *.xcconfig files or config.h headers. This is not possible with a "Run Script Build phases", since dependency tracking takes place before any build phase is triggered.

  2. Post build scripts
    Similar to above, but running after the build finished (including code signing etc). Useful for additional packaging, validity checking etc.

  3. Pre/Post SCM Commit scripts.
    To check project integrity.

  4. Pre/Post File Save Script.
    To check/alter a file before saving. E.g. run cody beautifiers

  5. Custom project actions.
    I'm aware of the organizer's ability to define arbitrary actions. But this is a per user feature (not part of the project). I'd like to define actions like build or clean that show up in the build menu and that are part of a project.


See here for Xcode4: http://www.wezm.net/technical/2011/08/strip-trailing-whitespace-xcode-4/

이제 Mac 용 Google 도구 상자에 Xcode4에 대한 "공백 자르기"옵션이 추가되었습니다.

http://code.google.com/p/google-toolbox-for-mac/downloads/list

감사합니다, Google!

참고 URL : https://stackoverflow.com/questions/1390329/trim-trailing-spaces-in-xcode

반응형