-
3 votes
-
Make Emacs write (part of) your git commit messages
I was fed up with the chores of writing consistent git commit messages, so a while ago I started developing a hook in Emacs which I used with Magit (actually git-commit-mode) which uses some crude...
I was fed up with the chores of writing consistent git commit messages, so a while ago I started developing a hook in Emacs which I used with Magit (actually
git-commit-mode
) which uses some crude heuristics to fill out theCOMMIT_EDITMSG
buffer for me. Here is what it does (|
stands for the cursor):-
If only a single file modified, insert
<filename>: |
- If can figure out function name, insert
<filename> (<functionname>): |
- If can figure out function name, insert
-
If only a single file added, insert
Add <filename>|
-
If a
TODO
added toReadme.org
, insert; TODO <headline>|
-
If a
TODO
wasDONE
, insert; DONE <headline>|
-
If the files are
Readme.org
andReadme.org_archive
, and no new TODO's were added anywhere, insert; Archive DONE|
-
If the file is
.gitignore
, insert; Ignore |
-
If the file is
TAGS
, insert; Update TAGS|
I extend this when I find new cases where I repeatedly do the same thing. The code is below. It's probably a good idea to use it as a starting point and personalise it because this reflects how I like to write my commit messages (and I like pretending how they do it over at Emacs git repo). It is sloppy and probably buggy, but I don't think it can be destructive.
Final note: I can't figure out how to set this up so that after this takes effect, the buffer is marked as modified. I want to flip the modified bit so that in some cases I can just hit
C-c C-c
and go. But I need to modify the buffer somehow to commit in some cases (I just typeC-o
to open a new line in those cases). Here is the function:(defun gk-git-commit-mode-hook () "Set up git commit buffer." ;; If a single file is modified, prefix the message w/ it. (let ((modified-re "^# modified:") (new-re "^# new file:") (issue-re "^[+\\- ]\\*+ \\(TODO\\|DONE\\) ") current-defun filename addp onlyp issuep) (save-excursion (with-current-buffer "COMMIT_EDITMSG" (goto-char (point-min)) (re-search-forward "^# Changes to be committed:" nil t) (forward-line) (beginning-of-line) (cond ((looking-at modified-re) (re-search-forward ": " nil t) (setf filename (thing-at-point 'filename t))) ((looking-at new-re) (re-search-forward ": " nil t) (setf filename (thing-at-point 'filename t) addp t))) (setq onlyp (progn (forward-line) (not (or (looking-at modified-re) (looking-at new-re))))) (when (and onlyp (equal filename "Readme.org")) (goto-char (point-min)) (when-let* ((pos (re-search-forward issue-re nil t))) (setq issuep (progn (re-search-backward "\\*" nil t) (buffer-substring (1+ (point)) (line-end-position)))))) ;; Try to set ‘current-defun’. (when onlyp (save-excursion (goto-char (point-min)) ;; Error if not found, means verbose diffs ;; not enabled. (re-search-forward "^diff --git") (goto-char (line-beginning-position)) (let ((str (buffer-substring (point) (point-max))) (default-directory (expand-file-name ".."))) (with-temp-buffer (insert str) (diff-mode) (goto-char (point-min)) (setq current-defun (diff-current-defun)))))))) (if onlyp (cond ((and issuep (not addp)) (goto-char (point-min)) (insert ";" issuep)) ((equal filename "TAGS") (goto-char (point-min)) (insert "; Update TAGS")) ((equal filename ".gitignore") (goto-char (point-min)) (insert "; Ignore ")) (filename (goto-char (point-min)) (if addp (insert "Add " filename) (insert filename (if (and current-defun) (format " (%s)" current-defun) "") ": ")))) (when (and (equal filename "Readme.org") (save-excursion (goto-char (point-min)) (re-search-forward (concat modified-re " +Readme.org_archive") nil t)) (save-excursion (goto-char (point-min)) (re-search-forward "\\-\\*+ DONE" nil t)) (not (save-excursion (goto-char (point-min)) (re-search-forward "\\+\\*[\\+\\-] TODO" nil t)))) (goto-char (point-min)) (insert "; Archive DONE"))))) (add-hook 'git-commit-mode-hook #'gk-git-commit-mode-hook)
Hope you find it useful.
12 votes -
-
A new Lord of the Rings video game is coming in 2021
7 votes -
IMO, Trump 2020 is better than a non-progressive Democrat
In 2016, I was an ardent supporter of Bernie. But come the general, I voted 3rd party, because I was "Bernie or Bust." Many people accuse me of indirectly voting for Trump, allowing "the worst...
In 2016, I was an ardent supporter of Bernie. But come the general, I voted 3rd party, because I was "Bernie or Bust." Many people accuse me of indirectly voting for Trump, allowing "the worst thing ever" to happen (esp since I'm in a swing state that went Trump). But here's the truth as I see it: Voting Democrat regardless of candidate, with their only qualification being "Not Trump," will only increase the USA's slide (deeper) into fascism.
The reality I see is that even if Trump had never entered the 2016 race, 90%+ of the policy, judicial appointments, and everything else that he has done since being elected would be identical no matter which "R" candidate won the race, because all of these things are exactly what the GOP has been doing for decades. In that regard, I consider Trump more favorable than any other R candidate, because he is at least failing to do his "real" job: Hiding fascist, imperialist policy behind a charismatic smile and some clever words.
Ultimately, this is the reason why I don't generally support Democrats either. Hillary's policy wouldn't have been as immediately destructive as the GOP agenda, but it also would not have stopped the march towards fascism. I voted my conscious in 2016, and will do so again in 2020. I just hope there are more people willing to do the same this time around.
I like to picture that the government of the USA is digging a hole. With every shovelful, we're sliding ever closer to a fully authoritarian fascist regime, and the destruction of our planet. While Trump (and the GOP as a whole) has been calling in for backhoes and drills to speed the process....as far as I can tell, only two candidates in the 2020 primary are calling to stop the digging: Elizabeth Warren and Bernie Sanders. At best, the other candidates are conveying messages akin to: "We need to compromise with the GOP and maybe slow down the rate at which we allow new backhoes to be brought to the pit."
In my mind then, it makes more sense for 4 more years of Trump, than to allow another center-right candidate for his opposition. Because at least Trump isn't able to pull off the charismatic smile and/or intelligent language that the Regan's, Bush's, Clinton's, and Obama's of the world have that allow terrible things to continue behind a cloak of "incremental change." It wakes up those who would otherwise tolerate these horrendous acts, and perhaps inspires them to become more active. By allowing for the political discourse to end with "Anything is better than Trump", it just permits the overall platform to gradually, but continually shift to the right.
And in my mind, it is the total death of real, dissenting voices in public discourse that is far, far worse than Trump winning another term could ever be.
I would love to hear if anybody else in this community has had feelings akin to what I've described here, as I've only been described as "insane" by most of the people I've discussed this with in person.
30 votes -
Jobs in southeast Kentucky's coal mines are vanishing. Can green jobs replace them?
4 votes -
Mozambique floods cover more ground than NYC, Chicago, D.C., and Boston — combined
5 votes -
How To Boost Your Home Wi-Fi Signal
5 votes -
Edge-on-Chromium approaches; build leaks, extensions page already live
4 votes -
Kickstarter for Firmament, a "next-generation narrative adventure" from Cyan, has launched
5 votes -
Sample Story and new Patreon Page
5 votes -
Apple Special Event - March 25, 2019
19 votes -
Father of Sandy Hook shooting victim dies by apparent suicide
7 votes -
Jordan Peele’s 'Us' untethered $70 million from North American wallets this weekend
7 votes -
Best works from the Beat Generation?
Hello ! I've been interested in reading some works from famous Beat Generation authors like Jack Kerouac, William Burroughs, Carolyn Cassady, Allan Ginsberg, etc. I have yet to read any of their...
Hello !
I've been interested in reading some works from famous Beat Generation authors like Jack Kerouac, William Burroughs, Carolyn Cassady, Allan Ginsberg, etc.
I have yet to read any of their works but I'm not quite sure where to start. I've been thinking of 'On the Road' by Kerouac but the reviews I've been reading have been mixed. It doesn't seem like it's for everybody, especially considering the writing style. I've also been thinking of 'The Dharma Bums', also by Kerouac since it seems to be more spiritual, which is something that really resonates with me.
Anyway, if you have any recommendations/opinions I'd be more than happy to hear them. Thanks !!!
12 votes -
What is the VPN that works best for you?
I've lately been looking for a new VPN, mainly out of privacy concerns. My question is, what is the best VPN that has worked for you (either paid or free) and why?
22 votes -
Bigger than that - Complex thoughts on a life spent being the short guy
10 votes -
Mhern - Traveller (2018)
4 votes -
Brexit: MPs vote to take control of Brexit process for indicative votes
10 votes -
The rise of robot authors: Is the writing on the wall for human novelists?
4 votes -
A trojanized version of the ASUS Live Update Utility was signed and hosted on the official server and distributed to an estimated 1 million users
18 votes -
Better x86 Assembly Generation with Go
4 votes -
Transgender advocates 'gobsmacked' by 'uneducated' ad opposing Tasmanian birth certificate laws
8 votes -
Madvillainy at 15: MF Doom on the legacy of his classic madlib collaboration
7 votes -
No Man's Sky: Beyond — Virtual Reality
14 votes -
For sale: This massive, obsessive and (probably) obsolete VHS boxing archive
7 votes -
A history of pizza
11 votes -
PlayStation State of Play | March 25, 2019
3 votes -
Which Dracula film is most faithful to the book?
17 votes -
Neri Oxman's new glass printing technique could lead to 3D-printed glass building facades
7 votes -
Kill La Kill Frame Sketches
10 votes -
The fall and rise of partisan journalism
5 votes -
Why drinking can feel isolating when you have 'Asian glow'
16 votes -
NPR New Packet Radio: IP over 430MHz Ham Radio, up to 500kbps, 20W RF. Extension for HSMM-Hamnet. 100% open-source.
9 votes -
Tame Impala - Patience (2019)
13 votes -
Venus is not Earth's closest neighbour
17 votes -
Tegan And Sara - Goodbye, Goodbye (2013)
5 votes -
Post something that you want to get into but don't know how, and have other people give you advice
Example: I'd like to learn more about wine1, but it seems very complicated and its hard to tell what's "real" and what's just stuff people have made up to be pretentious. I recognize this isn't a...
Example: I'd like to learn more about wine1, but it seems very complicated and its hard to tell what's "real" and what's just stuff people have made up to be pretentious.
- I recognize this isn't a "hobby" per se but I think it fits best in this group
41 votes -
The hunt for black gold: Is California the world's next truffle hotspot?
5 votes -
US Attorney General William Barr releases Robert Mueller Report’s principal conclusion
29 votes -
No Man’s Sky Online announced, coming as a free update this summer
15 votes -
How does compression work? A short explanation.
8 votes -
The future of depression treatment
5 votes -
RIVVRS - More Than A Fool
6 votes -
Telegram now allows every Telegram user to delete any message in a private conversation from both sides
23 votes -
Uber, Lyft drivers strike for higher pay in Los Angeles
8 votes -
La Pampa: The illegal mining city Peru wants wiped out
11 votes -
Multiple upcoming Bethesda games will be released on Steam, as well as Fallout 76 (currently exclusive to Bethesda launcher)
@bethesda: We're pleased to announce that RAGE 2, Wolfenstein: Youngblood, Wolfenstein: Cyberpilot, and DOOM Eternal will be released on Steam as well as https://t.co/p0BARqmTBp. We will also be bringing Fallout 76 to Steam later this year.
10 votes -
United Airlines announced it will be the first airline to offer nonbinary gender options for customers to book flights
8 votes -
Top Scores - From Pong to Red Dead: Can video game music change the way you play?
5 votes -
Royce da 5' 9'' - Cocaine
8 votes