Libinput is a library to handle input devices in Wayland and X.Org. It can be used as a drop-in replacement for evdev and synaptics in X.Org, and it is supported by a wide range of desktop environments, including GNOME and Xfce. In this post, we will see how to enable natural scrolling for trackpads using libinput. We will also leave mouses alone, i.e., no natural scrolling for mouses.
First, we need to know the name of the trackpad to enable natural scrolling for. This can be easily known by executing
xinput --list. My output includes the following:
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ bcm5974 id=13 [slave pointer (2)]
It is easy to see that my trackpad is
Git is a popular version control system that manages many impacting open source projects. Many of these projects, such as Linux kernel, zsh, GNU Emacs, etc. require patches and pull requests to be sent to their mailing lists. This can usually be done via
git send-email or
git imap-send, which, however, often takes a large amount of configuration and headaches for many people to make it work for the first time. Here, I propose a new approach to send git patches via email with GUI email clients, such as Thunderbird, Evolution, Claws Mail and Apple Mail.
The make utility is an standard utility on POSIX systems (GNU/Linux, macOS, etc.) that update files derived from other files, such as compiling source files to their binary forms. It is widely supported and used across different fields such as organizing and building C/C++/Fortran projects, building Sphinx documentation, etc.
The most popular implementation of the make utility is probably GNU make, which is usually the default make program on various GNU/Linux distributions. (On macOS, the version of the default GNU make is pretty old. Please consult Install and Use GNU Command Line Tools on macOS/OS X for a newer version.) It adds one very important feature besides the standard make specification: parallelization. The command line option
-j can be used to specify the maximum number of jobs that it is allowed to run simultaneously. However, it is quite annoying to type up this option every time when using it—we want a setting such that the CPU can be fully utilized by default. To achieve this goal, add the following lines to your
~/.bashrc if you use bash or
~/.zshrc if you use zsh:
# set MAKEFLAGS
if type nproc &>/dev/null; then # GNU/Linux
export MAKEFLAGS="$MAKEFLAGS -j$(($(nproc)-1))"
elif type sysctl -n hw.ncpu &>/dev/null; then # macOS, FreeBSD
export MAKEFLAGS="$MAKEFLAGS -j$(($(sysctl -n hw.ncpu)-1))"
The code above sets the envrionmental variable
MAKEFLAGS, which specifies the command line arguments of any invoked make subprocesses. It is set such that the maximum number of jobs that is allowed to be run simultaneously is equal to the number of available CPU cores minus 1. In this way, the hardware is more or less fully utilized when using make, with one CPU core left for other potential tasks on the system.
When sending out an email, sometimes we just forgot to attach the attachments. An attachment reminder can largely prevent this: You are asked to confirm whether you have forgotten the attachments if your message body shows that you may need one. However, Emacs by default does not provide such a feature in its mail composing mode
message-mode, which is used in email clients such as gnus and mu4e. Here is an attachment reminder based on this comment:
(defun my-message-current-line-cited-p ()
"Indicate whether the line at point is a cited line."
(string-match (concat "^" message-cite-prefix-regexp)
(buffer-substring (line-beginning-position) (line-end-position)))))
(defun my-message-says-attachment-p ()
"Return t if the message suggests there can be an attachment."
(and (setq search-result (re-search-forward "\\(attach\\|pdf\\|file\\)" nil t))
(defun my-message-has-attachment-p ()
"Return t if the message has an attachment."
(re-search-forward "<#part" nil t))))
(defun my-message-pre-send-check-attachment ()
(when (and (my-message-says-attachment-p)
(y-or-n-p "The message suggests that you may want to attach something, but no attachment is found. Send anyway?")
(error "It seems that an attachment is needed, but none was found. Aborting sending."))))
(add-hook 'message-send-hook 'my-message-pre-send-check-attachment)
If “attach”, “pdf” or “file” are in the message you are sending, a confirmation would be required to confirm the attachments if they are not attached.
Matrix is an open standard for decentralized persistent communication, shares somewhat similar goals to Jabber/XMPP. It attracts people from using centralized communicating software such as Facebook Messenger, WhatsApp, etc. In the Matrix protocol, a piece of software called “homeserver” plays a key role to connect users. To use Matrix, one such server must be set up. In this post, we will set up Synapse, an implementation of the Matrix homeserver maintained by the Matrix team, using a minimal configuration on Ubuntu 16.04.
ls command is a command to list files on a UNIX-like system. It is probably one of the most used command. However, a plain
ls command without any polishing may look really “plain”. Here, we will slightly configure this command to make it more usable:
- More colorful output
- Automatic pagination for long file lists
- File type indication
- Human readable sizes
- Natural ordering of files
ls before configuration
ls after configuration
browse-url in Emacs can be used to start a browser process to visit a given URL. It is used by many packages such as
mu4e, etc. However, on GNU/Linux, by default a new browser process started by
browse-url will be killed if the Emacs process exits. To prevent the browser process from being killed, add the following code to your Emacs init file:
(when (and (executable-find "setsid") (executable-find "gnome-open"))
(lambda (url &optional ignored)
(start-process "" nil "setsid" "gnome-open" url))))
You will need both the
gnome-open commands available. Note that replacing
xdg-open is not guaranteed to work.
If installing Emacs from source, an executable named
ctags will be installed by default. However, many systems such as GNU/Linux, FreeBSD and macOS often already have an executable named
ctags installed, such as Exuberant Ctags or Universal Ctags, which then causes conflict. To avoid this conflict, we can use the switch
--program-transform-name='s/^ctags$/ctags.emacs/' when running
configure to rename
ctags.emacs. For example:
mkdir build && cd build
After that, running
make install will install the Emacs
ctags executable as
ElDoc mode is a minor mode that displays information about a function or variable in the text at point (cursor). However, by default, it displays the information in the echo area, which isn’t quite ideal since our eyes often need to traverse half of the screen to view that information:
In both bash and zsh, there are multiple methods to check whether a command exists. In this post, a set of speed tests will be performed on them to find the fastest way in each of the two shells (NOT to compare the two shells). We will test 5 different methods (
foobar is the command to test for existence in the list):
type foobar &> /dev/null
hash foobar &> /dev/null
command -v foobar &> /dev/null
which foobar &> /dev/null
(( $+commands[foobar] )) (zsh only)
All the methods listed above will have a return status of zero if the command
foobar exists, otherwise non-zero. That is, after replacing
testing-command by any of the commands listed above, you can test the existence of the command
foobar by executing
testing-command && echo exist || echo non-exist.
Throughout this post,
ls will be the command that is used for testing existence, which does exist on the system which runs the tests. The test environment is Debian Jessie with bash 4.3.30 and zsh 5.0.7 on Intel Xeon processor E3-1240 v3 (8 MB Cache, 3.4 GHz). The test scripts are also available at the end of the post.