Replacing Autokey in Wayland

Many Linux distros are leaving xorg (x11) for Wayland, as display server protocol. Unfortunately not all the applications are ready for Wayland.

In particular Autokey, a very useful application to expand text and automatize typing operations, is not (yet) compatible with Wayland.

A quite good replacement of Autokey is Espanso. But there are also some limitations:

  • Espanso has big problems in LibreWriter (abbreviations are often expanded with errors). Similar problems there were also with Autokey in LibreWriter, but Autokey was able to provide some workarounds.
  • Espanso, unlike Autokey, can provide a very small range of hotkeys (such as ctrl + alt + d): Espanso can use only hotkeys with ctrl (not with alt or shift) and a few letters. I.g. “x01” means “ctrl + a”. You can find the whole range of possible combinations here.

However, as long as the main typing operations are in LibreWriter, or Kate, you can use that applications possibilities to expand text.

in LibreWriter there are at least two possibilities (to expand an abbreviation):

  • tools – > autocorrect
  • tools -> autotext

In Kate you can use snippets to create something similar to Autokey.

I.g. to create a snippet to wrap selected text with the tag <h1>, you can add this code as snippet code:

${rangeCommand("<h1>%%1</h1>", "title")}

Choose the title as you prefer (obviously without spaces), and a key combination, i.g. ctrl+1.

Don’t forget to add, in the javascript section (the tab scripts) this code

function rangeCommand(command, def) {
    if (view.selectedText().length > 0) {
        return command.replace("%%1", view.selectedText());
    } else {
        return command.replace("%%1", def);
    }
}

In this way, you will be able to add a title <h1> to your selected text.

Google speech-to-text

If you use Google speech-to-text one problem is to type signs such as ‘(‘ or ‘)’. In English you can say (in a low voice) open bracket or close bracket. In Italian apri parentesi tonda o chiudi parentesi tonda: indeed saying only apri parentesi Google will type “apri parentesi” and not “( “.

Markdown editor

Unfortunately same of the best MD editors have critical limitations

  • Dynalist, i.g., would be an excellent md editor, but it forces you to use an online account (that means: a) you must be connected to the internet, and b) you share your data with Dynalist, and so your privacy goes away).
  • VNote too would be a good md editor, but it forces you to use its proprietary format (with only files in its own folder), and so you can’t open any existing md file.
  • LogSeq is very slow in starting, doesn’t provide a wysing editor, can’t edit long files, and, as the other above editors, it don’t let you open, modify and save existing md files.
  • Joplin is a bite better, but it too don’t let open, modify and save existing md files: you must use its folder, and its proprietary format.
  • Siyuan is anothe app that force you to use its folder and its proprietary format.
  • Obsidian is not able to open or save any md file, even though it uses markdown.
  • MdSilo is not a bad program, but is very basic.
  • MarkText would be quite good wysing md editor, quite similar to Typora, but unfortunately it is discontinued.
  • Typora is the best md wysing editor: it support css customization and symlinks, you can easily open and save your md existing files (wherever they are). But is is not open source, but a pay app.

KDE user dictionary

You can find it i.g. in your home folder, as hidden file with a name such as .hunspell_it_IT.

If you have many PC you can share it between your devices.

Regex find and replace a digit

To find only a single digit (such as “1”, or “2”) and replace (only) it, you have to add a plus after \d.

Something like:

(\d+)

(to find it) and

\1

to replace it.

For example you have to add a new element to these lines

1 some first text 
3 some other text
8 other text

You can use this regex

find: (\d+) replace: \n\1

as a result you will get


1 some first text 

3 some other text

8 other text

LibreWiter header and footer

This feature is very useful if you write a book: have headers page with the book title on left pages and chapter title on right pages, and page number at the bottom, for example.

  1. To add a header to a page, choose Insert – Header and Footer – Header, and then select the page style for the current page from the submenu.
  2. You can also choose Format – Page, click the Header or Footer tab, and then select Header on or Footer on. Clear the Same content left/right check box if you want to define different headers and footers for even and odd pages.
  3. Then you can add the field you want, such as page number or book title (with Insert -> Field).
  4. Inserting chapter title is a bit more complex: Choose Insert -> More fields and then click the Document tab. Click “Chapter” in the Type list and “Chapter number and name” (or “Chapter name”) in the Format list and select the level (typically the second one: “2”). Click Insert and then click Close.

Pop-up footnotes (at the window bottom)

A good starting point is the Hugo footnotes

But I have done some improvements (according to my needs), as the following:

  1. link (at the end of a html page) the file footnotes.js, with this content:
function getFootnoteContent(index) {
  const id = "fn:" + index;
  const fn = document.getElementById(id);
  return fn.innerHTML.trim();
}

function footnotePopup(showIndex, showCloseBtn) {
  const popupWrapper = document.querySelector("#popup-wrapper");

  // Set whether to display index and/or close button. Default is true for both
  if (showIndex === undefined) {
    showIndex = true;
  }

  if (showCloseBtn === undefined) {
    showCloseBtn = false;
  }

  // Create main container that will hold footnote content
  const popupContent = popupWrapper.appendChild(document.createElement("div"));
  popupContent.id = "popup-content";

  let popupIndex = null;
  if (showIndex) {
    popupIndex = popupWrapper.insertBefore(
      document.createElement("div"),
      popupContent
    );
    popupIndex.id = "popup-index";
  }

  let popupCloseButton = null;
  if (showCloseBtn) {
    popupCloseButton = popupWrapper.appendChild(document.createElement("div"));
    popupCloseButton.innerHTML = "[x]";
    popupCloseButton.id = "popup-close";
  }

  // Remove redundant [return] links from footnote list (optional)
  const fnReturns = document.querySelectorAll("a.footnote-return");
  fnReturns.forEach(function (fnReturn) {
    const parent = fnReturn.parentNode;
    parent.removeChild(fnReturn);
  });

  const fnRefs = document.querySelectorAll("a[id^='fnref:']");
  fnRefs.forEach(function (fnRef) {
    fnRef.addEventListener("click", handler("refs", fnRef));
  });

  //window.addEventListener("scroll", handler("close"));
  
  document.addEventListener(
    "click",
    function (event) {
      if (
        event.target.matches("a[id^='fnref']") ||
        event.target.matches("#popup-content")
      ) {
        return;
      }
      popupWrapper.style.display = "none";
    },
    false
  );

  if (showCloseBtn) {
    popupCloseButton.addEventListener("click", handler("close"));
  }

  function handler(type, node) {
    console.log("test");
    return function (event) {
      if (type === "close") {
        popupWrapper.style.display = "none";
      }

      if (type === "refs") {
        event.preventDefault();

        const index = node.id.substring(6);

        if (showIndex) {
          popupIndex.innerHTML = index + ".";
        }

        popupContent.innerHTML = getFootnoteContent(index);
        popupWrapper.style.display = "flex";
      }
    };
  }
}

footnotePopup(false, true);
 

2) Put, before that link, the div where the note will be shown

<div class=\"bottom-panel\" id=\"bottom-panel\">
 <div class=\"popup-wrapper\" id=\"popup-wrapper\"></div>
</div> 

3) Modify the anchor tag (within your main text), with something like

<a href="#n1" id="fnref:1">[1]</a> 

4) and the footnote should be like the following:

<p id="fn:1"><a href="#fnref:1">[1]</a> your footnote here.</p> 

Update a mysql table replacing it

Replacing a table with the same name, I mean. You have to add, before “CREATE TABLE tablename” this row:

DROP TABLE tablename;

You can also add single rows, exporting them, and importing in a sql query, like the following:

INSERT INTO bibliografie (ID, autore, autore_nome, titolo, imagelink, sigla, tipologia, curatori, curatore_unico, opera, rivista, num, pagg, edizione, luogo, data, data_spec, trad_titolo, trad_edizione, trad_luogo, trad_data, contenuti, keywords, reperibilita, letto, letto_quando, valutazione, riferito, destinazione, ambito, href, ad_code) VALUES
(1880, 'Godechot', 'Jacques', 'La Révolution française : chronologie commentée, suivie de notices biographiques sur les personnages cités', NULL, 'Godechot [1988]', 'libro', NULL, NULL, NULL, NULL, NULL, NULL, 'Perrin', 'Paris', '1988', NULL, 'La Rivoluzione francese. Cronologia commentata 1787-1799', 'Bompiani', 'Milano', '2001', '', 'Rivoluzione francese ', NULL, NULL, NULL, NULL, NULL, NULL, 'storia', NULL, NULL);