Showing 73 to 76

Noob Guix' Checklist

Computing

AIMED AT: users who have gone through the basics and installed the system, but are still confused about things

Guix has not much in the way of end-user tutorials that tell you how to operate in day-to-day life. So you easily miss obvious things. We can't learn everything all at once nor see the best way to work even if we know roughly what commands exist. What follows would have prevented problems I had for far too long. Give it a gander in case you are suffering like I did.

I'd like to grow this list. If you have suggestions, email me!

Root vs user profile ??? I'm confus!

No, you don't need to run guix pull both as root and as your main user. Here's a full system upgrade:

guix pull
guix upgrade
sudo -E guix system reconfigure ~/config.scm

Using sudo with the -E flag means you'll be using the user's copy of Guix, thus root does not need to do a guix pull. Do remember that root's copy is outdated if you ever log in to root on a tty (just don't do that).

(<2022-Jan-23> OK, pretty sure the -E flag is not even needed)

Loading

How best to load your own package definitions? In short:

  1. Don't set the shell variable GUIX_PACKAGE_PATH – forget about it altogether – instead, set up a private channel (see the manual).
  2. In addition, be familiar with the -L (--load-path) flag.

That's because you are solving two separate problems:

  1. Always having access to your privately defined packages
  2. Quickly iterating on new definitions

Quick iteration from a private channel is slow, because as of <2020-Mar-22>, guix pull does not have a setting to only pull the local channels, so you have to wait for it to update all your channels, pulling things over the network and calculating a new package graph, and god forbid there's actually an update to Guix.

In principle, GUIX_PACKAGE_PATH solves both problems, but it introduces its own problems: Guix gets no ability to version-control your packages (as it does with a channel), it's a bigger hurdle to publish your packages, and as of <2020-Mar-22>, it causes every Guix command to complain a lot about "source file newer than compiled".

Ok, show me

So, let's assume you have this directory structure for files containing your package definitions:

~/my-channel/me/emacs-xyz.scm
~/my-channel/me/machine-learning.scm
~/my-channel/me/various.scm
~/my-channel/.git

Those *.scm files contain the top-level expressions (define-module (me emacs-xyz)) and (define-module (me machine-learning)) et cetera – the module names have to match the file and directory names.

Next up, the following content of ~/.config/guix/channels.scm will give you access to your packages. Plug and play.

(cons*

  (channel
    (name 'me)
    (url "file:///home/me/my-channel/.git"))

  %default-channels)

That's all good when your package definitions work. But when I am writing a new package, I run into errors maybe twenty times before I get it right. So during this process of iteration, instead of repeatedly git-committing and guix-pulling, load the directory directly, sidestepping the whole channel concept:

guix package -L ~/my-channel -i MY-EXPERIMENTAL-PACKAGE

Or, for example

guix build -KM 5 -L ~/my-channel MY-EXPERIMENTAL-PACKAGE

That's it. The additional flags are a bit off topic here, but -M 5 (--max-jobs=5) simply lets there be 5 concurrent build jobs so it'll build faster. The -K (--keep-failed) means that on a failed build, it'll tell you the path to the build directory, so you can see what got built and what didn't, what the configure variables are etc. An use case is when you're trying to modify a Makefile procedurally in the package definition (e.g. delete a few lines) and want to visit the actual Makefile to check that the modification had the intended effect.

I recommend shortening all that to a quick command, let's call it "test":

alias test="guix package -KM 5 -L ~/my-channel -i "

Then you can just run test PACKAGE every time you edit the definition for PACKAGE.

How to get help

You often find no help by Googling? Here are two places to get info, far more reliable than a generic web search:

  1. The #guix IRC channel logs
  2. The mailing list archives, particularly help-guix but also bug-guix lists.gnu.org/archive/html/

Download the entire chat log of the #guix IRC channel. Many, many times I've got answers by ripgrepping that directory.

Manpages

Especially when you keep separate package profiles/manifests, you might find Man pages and info documentation absent. To fix, every manifest (in addition to the main user profile & the system-wide profile) should contain at least the following packages:

  • man-db
  • info-reader
  • pkg-config

I'm not sure if there's a better way to do this.

Created (5 years ago)

Eshell's unnamable quality

There are many great packages. Packages like smartparens and company, that extend Emacs with invaluable functionality. But some packages are special, because they do more… they extend Emacs' extensibility. They increase Emacs' potential, make it applicable to more domains, let you slurp up more of your operating system and add opportunities for code reuse.

Some of them are:

  • eshell
  • exwm
  • exwm-edit
  • piper

These packages touch on a grander concept I will introduce shortly, but first I must explain what I see in Eshell.

The Way of Eshell is to abandon the concept of a terminal emulator, abandon the past and move into the future. The project has no plans to support escape codes (aka control codes) or interactive behavior, because controlling the shell buffer in realtime is considered out of scope for commands run by the shell.

Commands should be simple input-output machines and have no knowledge about their context. There is no need for each command to have twenty different command-line flags to shape the output into the form you want it – that's better done by an universal text-shaping tool, such as a text editor. You can alternatively use Unix commands like uniq, column and sort, but once you've exhausted what the commands can do, you may still have to make ad-hoc changes to the output as if in a text editor, so why not be in a text editor while you're doing it?

And better, once you're done editing the output with your everyday text-editing skills, you should be able to pipe it into another command without running into doubts as to which combination of echo, tee, xargs and cat applies this time (doubts strong enough that many have never thought of piping into vi). So you get to have a command pipeline without having to execute the pipeline in one step!

You don't need to iterate in a "compile-cycle" process until you get the whole pipeline just right. You can see what happens at each step, you don't need to pollute your shell history with irrelevant failed attempts, you can hone your text-editing arts, you'll have access to all the info your editor knows (say, the name of the file that's currently open in another window), you don't need to look up the specific shell commands to extract a specific piece of git information or system information (because you can get that info the same way you always do in your editor), and you'll never need to learn about commands like uniq, column or sort, or for that matter what even is Unix. Unix-nostalgia aside, that is scalable, beautiful and future-proof.

When you learn to abandon the Unix tools in favour of a more reusable and extensible workflow, you'll glimpse the deeper Zen underlying Emacs. The article Programs Are A Prison explains better than I can. Notice that it mentions that a good program should be "invisible", that it should lack boundaries, and eshell is a vivid example of that. Eshell is a much less distinct "application" than an external terminal window, and less distinct than ansi-term and even the polite shell mode. There is less of a sense that "Now I'm in the shell" or "Now I'm out of the shell". Its buffer is as malleable as any other buffer, and since you may do part of your command editing in separate buffers from eshell itself, it blurs the boundary of where the shell begins and ends.

What links here

Created (5 years ago)

Emacs gotchas

#emacs

Do not nest unlabeled with-restriction

Gotcha! This prints 1, not 100!

(save-excursion
  (with-restriction 100 500
    (with-restriction 300 500
      (message "inner restriction starts at %s" (point-min)))
    (message "outer restriction starts at %s" (point-min))))

Explanation

Unlike many other similar macros, like with-current-buffer or save-excursion, the with-restriction is not nestable. The innermost call undoes all the others.

Basically, if you don't use the :label argument, you may as well just use narrow-to-region and widen and reason accordingly. That'll be clearer code, I think. More verbose, because this macro is effectively a shorthand for

(unwind-protect
    (progn
      (narrow-to-region 100 500)
      ...)
  (widen))

and it's true, that a shorthand is handy. I might suggest that the shorthand have a different name though, that better communicates that it's not nestable. Like widen-on-exit. It could signal an error if it was in fact nested!

Once that exists, with-restriction could make mandatory the :label argument. Win win.

What should I use instead?

(save-restriction
  (narrow-to-region 100 500)
  ...
  )

That's what I thought with-restriction did.

For emacs-devel

Two ideas

  1. with-restriction, called without :label, signals an error if called twice, OR
  2. with-restriction, called with or without :label, signals an error if operating on an already narrowed buffer that wasn't narrowed by with-restriction with :label

gc-cons-threshold appears stuck on a value🔗

Probably your config uses gcmh-mode (e.g. Doom Emacs has it). Disable it, then you're able to fiddle with gc-cons-threshold.

Although with gcmh-mode you shouldn't need to fiddle. It's a great package. I just needed to fiddle when I was performance-profiling some code and worrying how people on lower settings would experience my code. Because not everyone has gcmh.

Pull gcmh into core and no one will have to think about this again.

Truncating the output of float-time in a format string🔗

This can result in confusing messages.

Because float-time or time-to-seconds (and, I infer, any Elisp function at all that returns a number) can represent the returned number in "scientific notation" like this: 2.4863e-05s instead of 0.000024863… then if you do this pattern:

(let ((T (current-time))
 (message "Elapsed: %.4s secs" (float-time (time-since T)))

then you'd see the message

Elapsed: 2.48 secs

when you'd really expect this:

Elapsed: 0.00 secs

The solutions for you and me:

  1. For anything to do with printing time, use format-time-string if possible.
  2. In format, message, error etc, don't assume %s does what you expect. For numbers, there's always a more specific %-sequence. In this example, write %.2f instead of %.4s.
  3. Double-check how you use number-to-string, prin1-to-string.

The solution for Elisp itself to stop confusing future devs is… maybe just not allowing the %s construct in format?

The funny thing is that the docstring of number-to-string says "return the decimal representation of NUMBER as a string". I guess I was wrong to think of decimal as not implying scientific notation:

(number-to-string 2.4e-05)
=> "2.4e-05"

Hide symbol from the global namespace🔗

Here's a way to "hide" a function named SYM, and a way to reveal it later:

(defvar dei--obarray (obarray-make 999331))

(defun dei--hide-function (sym)
  (fset (obarray-put dei--obarray (symbol-name sym))
        (symbol-function sym))
  (obarray-remove obarray sym))

(defun dei--reveal-function (sym)
  (fset sym (symbol-function (obarray-get dei--obarray (symbol-name sym)))))

Can I separate Tab from C-i?🔗

The manual says it all, at (emacs)Named ASCII Chars. Emphasis mine:

<TAB>, <RET>, <BS>, <LFD>, <ESC>, and <DEL> started out as names for certain ASCII control characters, used so often that they have special keys of their own. For instance, <TAB> was another name for ‘C-i’. Later, users found it convenient to distinguish in Emacs between these keys and the corresponding control characters typed with the <Ctrl> key. Therefore, on most modern terminals, they are no longer the same: <TAB> is different from ‘C-i’.

Emacs can distinguish these two kinds of input if the keyboard does. It treats the special keys as function keys named ‘tab’, ‘return’, ‘backspace’, ‘linefeed’, ‘escape’, and ‘delete’. These function keys translate automatically into the corresponding ASCII characters if they have no bindings of their own. As a result, neither users nor Lisp programs need to pay attention to the distinction unless they care to.

If you do not want to distinguish between (for example) <TAB> and ‘C-i’, make just one binding, for the ASCII character <TAB> (octal code 011). If you do want to distinguish, make one binding for this ASCII character, and another for the function key ‘tab’.

With an ordinary ASCII terminal, there is no way to distinguish between <TAB> and ‘C-i’ (and likewise for other such pairs), because the terminal sends the same character in both cases.

Have you ever wondered if you could unbind C-m without unbinding RET (or C-i without unbinding TAB)? The answer is no. Even on GUI Emacs, those are the same key; however, you can bind <return> to whichever command RET was bound.

The annoying part is that various major and minor modes might include a rebinding for RET but forget to include one for <return>, and that's why it doesn't always behave as you'd expect.

It isn't even a solution to hack the default function-key-map, because what you really want is for <return> to map to RET but not to C-m, but for that to be possible C-m would have to not be a synonym for RET.

The Emacs devs did succeed in decoupling C-h from DEL, so you could look up how they did that.

A misunderstanding of frames-only-mode🔗

I liked the idea of frames-only-mode, so when I tried out the tiling WM Sway, coming from EXWM, I added it. However… it did the exact opposite of what I imagined.

Here's the thing. There are two ways of achieving a "frame-based" workflow.

  1. The first way is to advise everything to create or destroy a frame: what frames-only-mode does. This enables a proliferation of frames – you could end up with dozens, and most frames in your workspace will be fairly recently created. Then it's up to your WM to keep most of them hidden most of the time.
  2. The second way is to never create or destroy a frame, much like Emacs' internal WM never creates more than 2 windows for you. Instead, you just prepopulate your workspace with the amount of frames you want, then configure display-buffer-alist to almost-always call display-buffer-use-some-frame. (And maybe fset the various siblings of display-buffer-in-side-window to the same.) With this, you could still be on the same 2-4 frames after weeks of uptime.

M-next

For people who like the PageUp/PageDown keys:

I rarely use C-v, and as a result, I also rarely used C-M-v (scroll the other window) and had to switch window to scroll it. In retrospect that feels fairly dumb… I never realized that M-<next> works! (Alt + PageDown) Instant love affair.

Digression: We could use a variant of the built-in tutorial that talks about these keys instead of C-M-v.

You can ignore org-modules

I thought there was something special about the variable org-modules… but no. It's just a non-programmer's way to require packages. If you want to load the org-id module you can just call (use-package org-id) at some point. No difference! I know that must be unsurprising to some of you, but hopefully a relief to others like me who labored under a different impression.

xinit emacs failure

Reasons:

  1. font-terminus wasn't installed, so naturally the line exec emacs -fn "Terminus 9" led to X closing (without informative errors!)

The concept of a "Symbol"

Disclaimer: This is not quite right, but I wrote this in 2019. I'm letting it stand as a record of what confuses newbies.

In Lisp, a "symbol" means what you might call a kebab, because they look like kebabs (example: elisp-slime-nav-mode-map looks like a stick with five food pieces on it). It's anything that's not a variable or value.

Examples of values:

  • 4
  • "some text"
  • "a"
  • nil
  • #<buffer emacs-gotchas.org>

Examples of variables:

  • a
  • b
  • fill-column
  • key-translation-map

Examples of function calls returning a value

(current-buffer)  ;; returns e.g. #<buffer emacs-gotchas.org>
(list a b)  ;; returns a list containing values 4 and "some text"
(list 'a 'b)  ;; returns a list containing symbols a and b
(setq a 4)  ;; returns 4, not that you often use the return value from setq
(setq b "some text")  ;; returns "some text"

Examples of symbols:

  • 'setq
  • 'key-translation-map
  • 'list
  • 'current-buffer
  • 'a
  • 'b
  • 'fill-column
  • 'add-to-string
  • '4
  • '"a"

But '(add-to-string testvar "a" "b") is not a symbol, because with the apostrophe in front of the paren, it returns a list of the four symbols add-to-string, testvar, "a", and "b".

The apostrophe out in front '(...) is a shorthand for (quote (...)) which tells the Lisp interpreter not to evaluate (...) as a function call.

Evaluating (concat testvar "a" "b") would instead return a single string. If testvar contains "foo", then evaluating that expression gives us "fooab".

If you were to instead attempt (list (concat testvar "a" "b")) it would first call the concat function, so it is the same as just running (list "fooab"). The "quote" function is a macro just for preventing this from happening, and important enough in Lisp that it gets a shorthand.

The most important gotcha: the above isn't always true, because many macros allow you to get away with not quoting things. Common are setq and use-package, which implicitly quote the first argument, like this:

(setq a "some text")

actually runs the following code

(set 'a "some text")

The word "setq" is short for "set-quote".

To undo key-translations

Suppose you have these settings in place.

(define-key key-translation-map (kbd "[") (kbd "("))
(define-key key-translation-map (kbd "]") (kbd ")"))

To undo them and revert to the normal state of affairs,

(define-key key-translation-map (kbd "[") nil)
(define-key key-translation-map (kbd "]") nil)

Rebinding tab, esc and return

Emacs has no less than five Enter keys, each of which do slightly different things (C-o, C-j, C-m, <return> and RET). It also makes a distinction between the keys "<escape>" and "ESC", which are located on the same key, so if you must be sure about inputting the latter, you can press "C-[" as a synonym…

For fun, check what all of these return:

(kbd "<iso-lefttab>")
(kbd "S-<iso-lefttab>")
(kbd "<tab>")
(kbd "S-<tab>")
(kbd "TAB")
(kbd "S-TAB")
(kbd "C-i") ;; same as TAB
(kbd "C-S-i") ;; same as S-TAB

In short, in graphical Emacs you're supposed to bind <tab> (for tab) and <S-iso-lefttab> (for shift-tab), though keeping in mind it will not have an effect on C-i, which will continue to be a synonym for TAB, which is what the tab key inputs on console emacs, and which may or may not have been bound to the same thing <tab> is bound to.

The Return key emits <return> in a GUI frame, and RET in a console frame. C-m always emits RET.

Emacs contains some hacks to make C-h do something different from DEL (backspace), ordinarily on Unix systems they are considered the same key.

Setting a variable from inside a function

Broken function, showing why you need a macro. Doesn't set the variable globally, it stays at its previous value (but it will work on variables defined by defvar).

(require 'subr-x)
(defun add-to-string* (string &rest additions)
  (setq string (concat string (string-join additions))))

This works.

(defmacro add-to-string (string &rest additions)
  `(setq ,string (concat ,string ,@additions)))

PS: to see what the macro expands to, another gotcha:

;; to see what the macro expands into, do this WITH apostrophe out front:
(macroexpand '(add-to-string testvar "a" "b" "c"))

In this example, (add-to-string testvar "a" "b" "c") actually runs (setq testvar (concat testvar "a" "b" "c")) – that's what a macro is, it translates code before running it.

Sexpwise editing also operates on symbols when given no sexp

Self-explanatory.

Keyboard macros and Lisp macros are different things

Self-explanatory.

What links here

Created (6 years ago)

Truncated data

#statistics

Truncation deals with missing data from part of a distribution:

A histogram that appears to take a Gaussian form except a part is cut off, with a Gaussian curve superimposed that ends up not matching

A histogram that appears Gaussian except a part is cut off and the missing bars are collected into one tall bar

Censoring is when the data is not missing, but the true value below a certain level is unknown so all observations take the same value when below that level (e.g. everything below -2 takes on the value -2), which practically increases the count of that one value, looking odd in the following histogram.

invertable.smoke1a 2019-01-12 16-17-46

The difference between censoring and truncation, then, is that in censoring we still have access to whole observations, being blind only to the dependent variable, whereas in truncation those observations are dropped altogether so we don't even have access to the independent variables.

Tobit?

Sometimes you also hear the term Tobit regression. How does it differ? A sentence in the Stata blog post caught my eye:

For truncated linear regression, we can use the truncreg command, and for censored linear regression, we can use the intreg or tobit command.

Bam. Tobit is just a subset of censored methods. It doesn't say that on Wikipedia or almost anywhere.

Created (6 years ago)
Showing 73 to 76