Spacemacs Rocks Note Day 6
2017-11-01
A series of notes that I learn Emacs hacking. Org-capture, org-pomodoro; file encoding with utf-8; batch rename files in dired mode, seach and replace with helm-ag; flycheck; snippets auto complete.
Use org-capture to take notes
- A module in org-mode. We can customize the template to make it easier to use.
- Configuration of the template.
1
2
3
4
(setq org-capture-templates
'(("t" "Todo" entry (file+headline "D:/Dropbox/AGDA/Orz.org" "Agenda")
"* TODO [#B] %?\n %i\n"
:empty-line 1)))
- Use
C-c C-sto add timestamp to the TODO item. Enter a time to schedule. - Use
C-a ato view the scheduled TODO list. Remember to set the location value of theorg-agenda-files.
1
(setq org-agenda-files '("D:/Dropbox/AGDA"))
org-pomodoro: A package to track the time. Pomodoro Technique.M-x org-pomodoro: Execute this command to start 25-min clock counter.
Miscellaneous optimization
- Change the default buffer encoding. So that in case we type some Chinese characters, the coding of the buffer will becomes “UTF-8”. And we don’t need to bother again typing the encoding when we save that file.
1
(set-language-environment "UTF-8")
- Insert current url of the first activate tab in Chrome (This is only achieved in Mac in the video). Try to implement that in Windows.
- Use
C-nandC-pinstead ofM-n,M-pto select the candidates in company-mode:
1
2
3
4
5
(with-eval-after-load 'company
(define-key company-active-map (kbd "M-n") nil)
(define-key company-active-map (kbd "M-p") nil)
(define-key company-active-map (kbd "C-n") #'company-select-next)
(define-key company-active-map (kbd "C-p") #'company-select-previous))
Batch rename files in dired mode
- Use
C-x C-qin dired mode. The major mode becomesEditable Dired. - Use
expand-regionandieditto batch change files. - Use
C-;to enter iedit mode. And then we can change the filename all together. - Use
C-c C-cto save the buffer to confirm the changes.
Search and replace (Important)
- Use
helm-ag: installagfirst
1
2
brew install the_silver_searcher
apt-get install silversearcher-ag
- Search speed:
ag>pt>ack>grep - Not quite convenient on Windows.
- Why not using
helmin Emacs?helmloads slower thanivy. However,helm-agis an exception. M-x helm-do-ag-project-root: find the occurence of certain keyword in the projoct directory.- We can bind a key to it. (
C-c p s). - type
!to eliminate the undesired results. - In the result buffer, press
C-c C-eenter editing mode. - Use similar things in previous section (Batch rename) to change everything at once!
Use flycheck to highlight typos
eslintfor JavaScript.- Install
flycheckpackage. - enable it globally:
(global-flycheck-mode) - Use
M-x flycheck-verify-setupto show the candidate flychecker module available. - Add more module to support more programming language.
- Option: Add hook to enable it only in programming mode instead of global mode.
About snippets.
yasnippet package
- Called
yasnippets. - It can help us to enter some commonly used code snippets, such as
for,while,if-else. - For more details, find the
YASnippetsmenu on the top in programming mode.
auto-yasnippet package
- Use
~to make the template. At that line, callaya-create. - At the new line, call
aya-expand, then we create a template that has multiple cursors marked at the previous~point. Type in the stuff you want and create a new sentence.