Posts tagged emacs


ELisp ebuilds good practices

:: elisp, emacs, gentoo, lisp, packaging

By: Maciej Barć

Check load path

Some Elisp package compilation failures are caused by not setting the loadpath correctly. It mostly happens when you compile source from a directory that is not the current working directory. For example:

1
elisp-compile elisp/*.el

In most cases you can cd or override the S variable to set it to location where ELisp source resides.

But in other cases you can append to load path the directory with source, see:

1
BYTECOMPFLAGS="${BYTECOMPFLAGS} -L elisp" elisp-compile elisp/*.el

Do not rename auto-generated autoload file

elisp-make-autoload-file allows to name the generated autoload file. For sake of easier debugging and writing Gentoo SITEFILEs, please do not rename the generated file.

The name of that file should always be ${PN}-autoloads.el.

Use new elisp-enable-tests function

elisp-enable-tests allows to set up IUSE, RESTRICT, BDEPEND and the test runner function for running tests with the specified test runner.

The 1st (test-runner) argument must be one of:

  • buttercup — for buttercup provided via app-emacs/buttercup,
  • ert-runner — for ert-runner provided via app-emacs/ert-runner,
  • ert — for ERT, the built-in GNU Emacs test utility.

The 2nd argument is the directory where test are located, the leftover arguments are passed to the selected test runner.

Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
EAPI=8

inherit elisp

# Other package settings ...

SITEFILE="50${PN}-gentoo.el"
DOCS=( README.md )

elisp-enable-tests buttercup test

Remove empty SITEFILEs

Recently a feature was added to elisp.eclass that will cause build process to generate the required SITEFILE with boilerplate code if it does not exist.

So if your SITEFILE looked like this:

1
(add-to-list 'load-path "@SITELISP@")

… then, you can just remove that file.

But remember to keep the SITEFILE variable inside your ebuild:

1
SITEFILE="50${PN}-gentoo.el"

Remove pkg.el files

The *-pkg.el files are useless to Gentoo distribution model of Emacs Lisp packages and should be removed. It is as simple as adding this line to a ebuild:

1
ELISP_REMOVE="${PN}-pkg.el"

Beware that some packages will try to find their ${PN}-pkg.el file, but in most cases this will show up in failing package tests.

Use official repository

It is tedious to repackage Elpa tarballs, so use the official upstream even if you have to snapshot a specific commit.

To snapshot GitHub repos you would generally use this code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# First check if we have the correct version to prevent
# autobumping package version without changing the commit.
[[ ${PV} == *_p20220325 ]] && COMMIT=65c496d3d1d1298345beb9845840067bffb2ffd8

# Use correct URL that supports snapshots.
SRC_URI="https://github.com/domtronn/${PN}/archive/${COMMIT}.tar.gz
    -> ${P}.tar.gz"

# Override the temporary build directory variable.
S="${WORKDIR}"/${PN}-${COMMIT}

Include live version support

We do not want to be worse than the Melpa unstable :D

So, why not allow the given package to be used live?

Even if you do not push the live package to the overlay, please include support for it.

1
2
3
4
5
6
7
8
if [[ ${PV} == *9999* ]] ; then
    inherit git-r3
    EGIT_REPO_URI="https://github.com/example/${PN}.git"
else
    SRC_URI="https://github.com/example/${PN}/archive/${PV}.tar.gz
        -> ${P}.tar.gz"
    KEYWORDS="~amd64 ~x86"
fi

Ask for tags

Git is good, git tags are good. In case if upstream does not tag their package or just forgets to, kindly ask them to create a git tag when bumping Emacs package versions.

Ebuild-mode

:: gentoo, portage, ebuild, emacs, tutorial, pkgcheck

By: Maciej Barć

Portage

Configure the following for Portage.

1
dev-util/pkgcheck emacs

Emerge

Emerge the following packages:

  • app-emacs/company-ebuild
  • dev-util/pkgcheck

Company-Ebuild should pull in app-emacs/ebuild-mode, if that does not happen, then report a bug ;-D

Standard

Add the following to your user's Emacs initialization file. The initialization file is either ~/.emacs.d/init.el or ~/.config/emacs/init.el for newer versions of GNU Emacs.

1
2
3
4
5
6
7
8
(require 'ebuild-mode)
(require 'company-ebuild)
(require 'flycheck)
(require 'flycheck-pkgcheck)

(add-hook 'ebuild-mode-hook 'company-ebuild-setup)
(add-hook 'ebuild-mode-hook 'flycheck-mode)
(add-hook 'ebuild-mode-hook 'flycheck-pkgcheck-setup)

Use-Package

We can also configure our environment using a use-package macro that simplifies the setup a little bit.

To use the below configuration the app-emacs/use-package package will have to be installed.

1
2
3
4
5
6
7
8
9
(require 'use-package)

(use-package ebuild-mode
  :defer t
  :mode "\\.\\(ebuild\\|eclass\\)\\'"
  :hook
  ((ebuild-mode . company-ebuild-setup)
   (ebuild-mode . flycheck-mode)
   (ebuild-mode . flycheck-pkgcheck-setup)))

The :defer t and :mode "..." enable deferred loading which theoretically speeds up GNU Emacs initialization time at the cost of running the whole use-package block of ebuild-mode configuration when the :mode condition is met.

KDE Emacs

:: kde, emacs, tutorial, customization

By: Maciej Barć

Proper window size

Sometimes while the Emacs GUI window is tiled to a side or maximized small gaps may appear around the window. This "bug" can be worked around by:

  • right-click on the title bar,
  • "More Actions",
  • "Configure Special Window Settings…",
  • "Add Property",
  • "Obey Geometry Restrictions",
  • Select "Force" form the combo box,
  • Select "No" from the radio buttons.

Opening files from Dolphin in one Emacs instance

Emacs daemon can help with that. But before you run emacs --daemon, I need You to know that there might be a better way:

1
2
(unless (or noninteractive (server-running-p))
  (server-start))

Adding the above to Your Emacs config will cause Emacs to start a daemon after it is opened (and no other Emacs servers are running), this also does not require --daemon flag.

After the daemon is started You can open files by right-clicking on them and selecting to open them in "Emacsclient".

Furthermore: You also utilize --iconic and add emacs --iconic to your Plasma startup. This is way better than using emacs --daemon because you can just click on your taskbar to open the minimized Emacs window. Also, Emacs will load all Your graphical libraries and configurations so Your theme will look properly and not as if Emacs was being used on the console.

Breeze theme

Sadly I have not found any theme that would look like Plasma. I use the spacemacs theme which looks a little bit similar, especially the background color comes close to Breeze's dark background color.

Note that the theme which You load with the function load-theme is a different thing that the GTK theme Emacs uses.

The GTK theme should be enabled if Your Emacs version is built with GTK support. On Gentoo this setting is controlled with the gtk USE flag. Also the flag toolkit-scroll-bars can be enabled for a look of scroll-bars consistent with the selected toolkit.

Xresources

There is a different approach to theming Your Emacs that loading a theme defined in ELisp - You can use a ~/.Xresource file.

If you do not load any theme in your configuration Emacs will by default read the .Xresources file, unless the --no-x-resources flag is used.

Here are a few Xresources config files that come close to the default Breeze theme:

Dbus integration

Emacs can be built with FreeDesktop's D-Bus support to communicate over the dbus protocol. This can come handy when using ERC as it has a setting to enable desktop notifications on mentions (erc-desktop-notifications.el).

The dbus interface can also be utilized to query desktop-oriented daemons, for example this library talks to the Bluetooth daemon.

KDE development

Those are some ELisp libraries that I found while browsing GitHub, they might be useful for somebody who delves into KDE app development.

Opening files in different applications

In addition to async-shell-command and start-process-shell-command I wrote this small library that may come handy.

Outside Emacs, inside Plasma

Sadly the KDE team did not add support to emulate Emacs-like keys in Plasma itself, but some applications like, for example Kate have configuration options to customize the key bindings. This is a repository explaining how to setup Kate's bindings.

Pkgcheck-Flycheck

:: emacs, pkgcheck, gentoo, ebuild, tutorial

By: Maciej Barć

News

Repository

With this commit first GNU Emacs integration was merged into the pkgcheck repository.

History

Thanks

Huge thanks to Sam James and Arthur Zamarin for support and interest in getting this feature done.

Installation

Unmasking

The Flycheck integration is unreleased as of now, this will (hopefully) change in the future, but for now You need live versions of snakeoil, pkgcore and pkgcheck.

File: /etc/portage/package.accept_keywords/pkgcore.conf

1
2
3
dev-python/snakeoil  **
sys-apps/pkgcore     **
dev-util/pkgcheck    **

Also You will need to unmask app-emacs/flycheck and its dependencies.

File: /etc/portage/package.accept_keywords/emacs.conf

1
2
3
app-emacs/epl
app-emacs/pkg-info
app-emacs/flycheck

Emerging

Install pkgcheck with the emacs USE flag enabled.

File: /etc/portage/package.use/pkgcore.conf

1
dev-util/pkgcheck    emacs

Afterwards run:

1
2
emerge -1av dev-python/snakeoil sys-apps/pkgcore dev-util/pkgcheck
emerge -av --noreplace dev-util/pkgcheck

Configuration

Following is what I would suggest to put into your Emacs config file:

1
2
3
4
5
6
7
8
(require 'ebuild-mode)
(require 'flycheck)
(require 'flycheck-pkgcheck)

(setq flycheck-pkgcheck-enable t)

(add-hook 'ebuild-mode-hook 'flycheck-mode)
(add-hook 'ebuild-mode-hook 'flycheck-pkgcheck-setup)

If You are using use-package:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
(use-package flycheck
  :ensure nil)

(use-package ebuild-mode
  :ensure nil
  :hook ((ebuild-mode . flycheck-mode)))

(use-package flycheck-pkgcheck
  :ensure nil
  :custom ((flycheck-pkgcheck-enable t))
  :hook ((ebuild-mode . flycheck-pkgcheck-setup)))

The lines with :ensure nil are there to prevent use-package from trying to download the particular package from Elpa (because we use system packages for this configuration).

HTML Renderers

:: browser, emacs

By: Maciej Barć

How it should be?

I imagine that a web browser should have been a "window" to the Internet world that provides easy and efficient way to graphically access resources exposed by multiple protocols: HTTP(S), (S)FTP, Gopher, Gemini, etc…

How it is?

Only few protocols are supported!

Recently FTP support got "deprecated" in Firefox. It can still be enabled in by setting network.ftp.enabled to true.

FTP support is announced to be completely gone in FF 90.

Chrome dropped FTP some time ago.

BUT!

Luckily we have Emacs!

GNU Emacs has packages to support all kinds of protocols.

  • eww which is a simple HTTP(S) browser like w3m (also renders images)
  • tramp allows you to access files by SSH
  • elpher allows you to access Gemini and Gopher sites (graphically)
  • ange-ftp allows you to connect to FTP servers
  • and finally net-utils which wraps around system utilities to provide interactive mode for many protocols, ie.: gopher, irc, ntp, pop3, www