Duplicate the current line in Emacs

Duplicate the current in Emacs Duplicating the current line is frequent editing for me when I am coding. Initially, I copied a snippet as a commend in Emacs from the Internet: (defun w/duplicate-line() "Duplicate the current line." (interactive) (move-beginning-of-line 1) (kill-line) (yank) (open-line 1) (next-line 1) (yank)) Most of the time, I was happy with it, but it has two drawbacks: It cannot keep the column position when moving to the next line [Read More]

Adjust the laptop's screen brightness from Emacs

Adjust the screen brightness from Emacs If you're using i3wm on Linux, how do you adjust the laptop's screen brightness? Most of the time, I use the laptop with an external monitor. But when I am out, I have no monitors. And it seems no easy way to adjust the brightness in i3wm. Being too bright or dim is terrible for the eyes. Recently, I found a command-line tool called brightnessctl, which can adjust the brightness in a terminal. [Read More]

How to kill other buffers in Emacs

Selecting Emacs windows using ace-window Recently I've been building a simple Emacs config for myself, along the way I re-discovered some fantastic packages, for example, I found that ace-window is a simple yet powerful package to enhance the default other-window command to select other windows quickly when it has more than two windows in a frame. I replaced the key binding of other-window to ace-window by simply (global-set-key (kbd "C-x o") #'ace-window), then when there are >2 windows, it will show a white-in-red number at the top-left corner for every window, press the number (1, 2, 3, …) and then the corresponding window is selected (as demonstrated in the above screenshot). [Read More]

How to append items to the CSV file without header row?

Scrapy Architecture Scrapy provides a few item exporters by default to export items in commonly used file formats like CSV/JSON/XML. I usually use CSV to export items, it is pretty convenient, and it comes in two ways: appending mode, for example, scrapy crawl foo -o test.csv overwriting mode with -O option, like scrapy crawl foo -O test.csv But in the appending mode, it's a bit annoying that it always appends the header row before the newly scraped items, which is not correctly in terms of CSV format. [Read More]

Eglot for better programming experience in Emacs

LSP, or Language Server Protocol, makes programming easier by features like better auto-completion and definition lookup. It may have scratched your itches, and you are wondering what the experience is like in Emacs. Emacs has mainly two LSP clients out there, eglot and lsp-mode. eglot is lightweight, and it could almost run out of the box. As a user, we only need to know these commands to get started of eglot: [Read More]

How to Reload i3status config On the Fly

Sometimes I want to change the status (i3status) of i3wm temporarily, but it seems that i3wm doesn't support it directly, although reloading the config for i3wm itself is a piece of cake (bindsym $mod+Shift+c reload in the config, or i3-msg -t command reload in the command line). But this issue scratched my itch, and I swear that I must solve it today. Following this Reddit post, it looks like it can be done by restarting the process of i3bar: [Read More]

Language Shadowing with subed in Emacs

So I'm trying to improve my English speaking skill by shadowing while watching TV episodes. The workflow before was to loop over video clips using mpv: hit l to mark the start of the loop play the video and wait for it to be at the end of the loop hit l again to mark the end Then mpv will loop over the clip, it basically works, but it's a bit hard and tedious to set the start and end precisely. [Read More]

Writing a Python Script in Emacs in 45 Minutes!

Note: watch my live coding session of this article: Intro If you've heard some rumors of Emacs that it has a very steep learning curve (or that Emacs makes a computer slow), you may be too scared to look at it. It indeed has some learning curve (learning anything does have one), but it isn't very steep. I learned this after getting my hands dirty with Emacs a few years ago. [Read More]

Beautiful Soup 4 Cheatsheet

Beautiful Soup Detailed docs: the Beautiful Soup 4 Docs. Want to scrape data from websites? I can help you: https://www.fiverr.com/share/j7qgrm Assume t is an object of Tag. Core concepts (classes) Tag, a Tag object corresponds to an XML or HTML tag. BeautifulSoup, the BeautifulSoup object represents the parsed document as a whole. You can treat it like a special Tag. [Read More]

Clojure reduce: one case for text processing

As a practice, I managed to illustrate Clojure files using illustrate.clj, but my original idea was to annotate org-mode files of blogs. It's not uncommon that a blog post has some code snippets. But it missed the feature until last night, as I wasn't sure how to implement it appropriately before and didn't have enough time. For example, I may have an org-mode like this: sum of two numbers: #+begin_src clojure(+ 1 2) #+end_src I want to have a result comment ((;; => 3)) after each top-level form after using illustrate. [Read More]