Join GitHub today
Note: this is a page of useful tricks for developers.
Remove Untracked Files
There are a lot of files that are in our
.gitignore file that stack up and don't gt cleaned. In order to remove every untracked file, including hidden ones, do this:
git clean -d -x -f
Warning: this will kill everything that's not currently being tracked. You probably want to run
git status first.
git-prompt.sh. This changes the prompt on the command line to show the current branch. Install by copying it to
/, follow install instructions. For a cleaner prompt, replace the PS1 suggested with:/stan" is the current directory, "(master)" indicates the current branch is the master branch.
PS1='\w$(__git_ps1 " (%s)")> 'The prompt will look like:
~/stan (master)>where "
git-completion.*sh. Install this for auto-completion from the command line. It auto-completes git commands and git branches. For example, type
git checkoutthen hit tab twice. It should show the available branches.
Aquamacs: single kill buffer
By default, aquamacs will has multiple kill buffers. This means that there is a copy and paste buffer by using command-c/x/v and there is a separate copy and paste buffer by using ctrl-w, alt-w, ctrl-y. This gets really confusing. Here's how to have a single kill buffer so copying from any Mac program will paste into emacs using ctrl-y or command-v.
- Open ~/.emacs (or wherever else you're storing your preferences)
(setq x-select-enable-clipboard t)
Fixing Line Feeds and Tabs
Ant includes a handy task called FixCRLF that "Adjusts a text file to local conventions." So you can set it to replace tabs with spaces and Windows line ends with unix ones.
To make sure you never have tabs in your code files, you can use this in your
(defun java-mode-untabify () (save-excursion (goto-char (point-min)) (if (search-forward "\t" nil t) (untabify (1- (point)) (point-max)))) nil) (add-hook 'java-mode-hook '(lambda () (make-local-variable 'write-contents-hooks) (add-hook 'write-contents-hooks 'java-mode-untabify))) (add-hook 'html-mode-hook '(lambda () (make-local-variable 'write-contents-hooks) (add-hook 'write-contents-hooks 'java-mode-untabify))) (add-hook 'cpp-mode-hook '(lambda () (make-local-variable 'write-contents-hooks) (add-hook 'write-contents-hooks 'java-mode-untabify))) (add-hook 'stan-mode-hook '(lambda () (make-local-variable 'write-contents-hooks) (add-hook 'write-contents-hooks 'java-mode-untabify)))
You can rename --- the "Java" in the title is a holdover from where I first got the macros.
You can also automatically remove line-final whitespace (this is just for C++, but it could be hooked elsewhere):
(add-hook 'c++-mode-hook (lambda () (add-to-list 'write-file-functions 'delete-trailing-whitespace)))