Blog overview

Latest entries:

2021-03-16: Code completion for emacs with LSP

1. Overview

There are a lot of packages for code development in emacs for a varity of languages, like cedet, company and others. The feature set starts from some keyword lookup for references, project handling, and code completion.

The language server protocol (LSP) is powerful,generic way to integrate IDE features into editors. For emacs, there is the lsp-mode which works great. There is excellent documentation at the homepage, but I wanted to write down some condensed steps to install it.

2. Installation

The simplest way to install is to use the emacs package manager and install the package "lsp-mode".

You need a LSP backend. For C there are two implementations, clangd is one of it so you might want to install that. It will be used automatically if it is available.

For a quick test, you can open a C file and execute "M-x lsp". I experienced a problem with an undefined symbol "-compose" which came from an old version of "dash" so you might want to update this package as well.

When opening a C file, emacs usually asks you to import the file as a project, you can press "i" to just import the current file or use "I" to manually set the project root directory which is often so better option. The project information are stored in the file

~/.emacs.d/.lsp-session-v1

3. Helping clangd to know about the project

clangd need to know how to compile the project and where to find include files etc. For this, a file named "compile_commands.json" must be created.

There are different ways to create such a file for different build environments. You can create the manually if you want to. For cmake you can use the option "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON". For make based project you can use the tool "bear" to create the file tool. Run "bear make" to create this file.

When everything is set up, you should be able to open any C/C++ file and start the lsp integration with "M-x lsp" (when applying the config in the next section, it will be done automatically). Then tab completion should just work if you have company active. You can also try to press M-. to jump to definition of a symbol.

4. Configuration

I use the following config to automatically enable lsp:
(add-hook 'c-mode-hook 'lsp-deferred)
(add-hook 'c++-mode-hook 'lsp-deferred)
(setq gc-cons-threshold (* 100 1024 1024)
      read-process-output-max (* 1024 1024)
      treemacs-space-between-root-nodes nil
      company-idle-delay 0.0
      company-minimum-prefix-length 1
      lsp-idle-delay 0.1)
(with-eval-after-load 'lsp-mode
 (add-hook 'lsp-mode-hook #'lsp-enable-which-key-integration))

5. Remaining issues

I experienced the following small issues:
  • I got a message
       Error running timer lsp--on-idle: (wrong-type-argument listp
       
    and it looks like it comes from the breadcrumb integration. You can disable the breadcrumb by running "M-x lsp-headerline-breadcrumb-mode" or disable it completely by using the configuration
       (setq lsp-headerline-breadcrumb-enable nil)
       
  • tab completion collides with yas-snipplet sometimes. I don't have a solution right now, you have to cancel the completion C-g and press tab again to get the yas-snipplet completion.
  • lsp sometimes asks for system includes to be part of the project, I don't know an other workaround than blacklisting them (the dialog allows to do that).

6. Final notes

This is just a very short version of how to install this mode but there is a nice tutorial at the "lsp-mode" homepage with a lot of more information.
tags: emacs2

2021-02-16: Installing OpenSuse Tumbleweed on an AMD Ryzen7 laptop with NVidia graphics

I recently bought a laptop with an AMD Ryzen7 4800H with hybrid graphics (Radeon and NVidia GTX 1650 Ti) and installed OpenSuse Tumbleweed.

I chose Tumbleweed over Leap 15.2 as I experienced serious issues with the older kernel shipped with 15.2. The system was not stable at all. Tumbleweed had kernel 5.9 at that time and currently runs 5.10 which works fine for the Ryzen CPU.

Basically everything worked out of the box with the exception of the proprietary graphics driver which is of course not installed by default. The rest of this artical describes the things I had to do to get everything working.

I have chosen this hardware combination since I wanted a powerful AMD Ryzen laptop CPU with powerful 3D graphics while still being small enough. I wanted to have a dedicated Radeon graphics to avoid proprietary nvidia drivers (which makes it hard to track down and fix stability issues), but there weren't any offers available so I opted for a NVidia card.

Since I don't care for battery time I choose to always use the dedicated graphics card. Otherwise I would have just used the integrated Radeon graphics of the 4800H CPU, which is reasonable fast for normal using.

Installation

First I booted and installed OpenSuse Tumbleweed from a current DVD image (on USB drive of course). During installation I chose NOT to install the nouveau driver since it did not really support the GTX 1650 Ti anyway and I want to use the proprietary driver.

At this point the integrated Radeon graphics should just work with AMDGPU driver.

I have added the nvidia repo to the opensuse repositories and install the package nvidia-glG05 and suse-prime. The later is for selecting which graphics card to use.

After a reboot, I ran

prime-select

to select the nvidia card for the main graphics card.

At this point, everything runs as expected. The CPU is fully supported by the kernel, WiFi/Bluetooth works, sound as well and the 3D driver is running fine.

Remaining issues

Hibernation

While suspend (to ram) worked out-of-the box, hibernate (or suspend to disk) did not work. The following steps are necessary to enable it:
  • Add "resume" to dracut configuration:
    vi /etc/dracut.conf.d/90-resume.conf
    add_dracutmodules+=" resume "
  • execute "mkinitrd" to create the new initrd.
  • add the kernel parameter so it knows where to restore from: yast -> bootloader -> kernel parameter
    resume=/dev/mapper/system-swap
    I'm not completely sure if this is necessary as dracut should take care if it.
After reboot you should be able to select hibernate from the lockin/lockout screen, but you can try it out manually be executing
systemctl hibernate

HDMI audio

Another thing which did not work directly was audio output over HDMI. Turned out the reason why it wasn't working was the prime-select package I have installed to be able to switch to the dedicated graphics cards. Otherwise it would probably just worked.

The reason why it was not working was a special udev rule set that have been installed by the package prime-select. To be able to disabled the dedicated graphics card on demand to reduce power usage and therefore increase battery time, the nvidia audio and usb devices had to be removed. Of course, since the audio device is removed, HDMI audio does not work.

I prefer to have HDMI audio working and don't care about battery life time, so I hat to remove the udev rule. One way is to deinstall the "prime-select" tool but I am not sure if this have some side effect for the nvidia driver. So I decided to just remove the udev file. Of course, whenever the prime-select package is updated, I have to remove it again.

For reference, the udev rule in question is the file

/usr/lib/udev/rules.d/90-nvidia-udev-pm*

USB autosuspend

Another minor issue is the USB autosuspend feature of the linux kernel. It has nothing to do with the opensuse installation itself, but this is something one might want to disable to be able to charge USB devices even if they are not in used.

You can disabled the power suspend individually for each USB device by writing "-1" into the autosuspend file in the /sys/ filesystem:

echo -1 >/sys/devices/pci0000:00/0000:00:1a.0/usb3/power/autosuspend
(of course adjust the address to the correct address of your device).

You can also disable it completely for all newly connected devices by writing "-1" to the file of the usbcore module:

echo -1 >/sys/module/usbcore/parameters/autosuspend
And you can also add a kernel parameter to disable it on startup:
usbcore.autosuspend=-1
Of course this will reduce battery life time a bit.

Final notes

One issue left is the use of hybrid graphics. In theory it should be possible to use the Radeon graphics as default and only use the NVidia on demand. For some little time I tried to play around with xrandr and the graphics provider settings but with no success. However, I do not care about this feature as I wanted to have a dedicated graphics anyway and the systems runs on main power most of the time.

2019-10-20: Terminal alternatives on Linux

I have used xterm for quite some time now since I want a simple terminal program that starts fast and keeps out of my way for most of the time. However, I miss some features from more advanced terminal programs so from time to time I take a look at alternatives.

I basically have the following requirements:

  • Fast startup: I start the terminal from within my file manager quite often when starting external programs or directly working on command line tools so fast startup is important to me.
  • Unicode/Ansi-Color support: The terminal must support unicode (utf-8 to be precise) encodings and must interpret ansi color codes.
  • Searchable scrollback buffer: I want to be able to search in the output of previous commands which makes it much easier to work with command line tools.

xfce4-terminal

Since I use XFCE as my desktop environment it was clear to at least try xfce4-terminal.

Pros:

  • nice color schemes out of the box
  • searchable unlimited scrollback buffer (Ctrl-Shift-f)
  • tab support
Cons:
  • it is reasonable fast when using dbus to start a new window from an already running process, but the window does not always open in foreground with focus. From time to time the new terminal is in the background and I have to switch windows to access it.
  • there is an option to not use existing process but then it is quite slow: Executing
       time xfce4-terminal --disable-server -x ls
       
    takes 0.25s on my i5-3120M with 8 GB of RAM

rxvt-unicode (urxvt)

Pros:
  • fast:
       time urxvt -e ls
       
    takes 0.07s
  • supports scrollback search (M-s)
Cons:
  • configuration is done with x11 attributes (.Xdefaults)
urxvt is my current choice as it is fast and supports search. Some fancy features like tab support is only available via perl extensions and configuration is little bit hard since a graphical configuration is missing. But once configuration is done, it just keeps out of the way and does its job.

Here are my x11 settings for .Xdefaults:

URxvt.foreground: #d3d7cf
URxvt.background: #2e3436
URxvt.saveLines: 1000000
urxvt supports Xft font rendering. You can select a Xft font as follows:
urxvt.font: xft:Misc Fixed:style=SemiCondensed:pixelsize=13

lxterminal

Pros:
  • reasonable fast
       time lxterminal -e ls
       
    takes 0.15s
  • graphical configuration and optional menu
  • tab support
Cons:
  • no searchable scrollback buffer

gnome-terminal

Pro:
  • graphical configuration and optional menu
  • tab support
Cons:
  • slow
       time gnome-terminal -e ls
       
    takes 0.3s

Other terminals

Here's a quick list of other terminals I checked:
  • mate-terminal: did not run without other mate components
  • sakura: simple terminal
  • terminology: fancy implementation but still only basic terminal support
  • terminus: another simple terminal
  • tilix: slow, but interesting multi-session, tiling concept. If you use screen or tmux but want a more graphical implementation, you may want to check this out.

All blog entries: all