hjertnes.blog

Getting started with Spacemacs.

21.02.2018 01:00

This post is intended for users that are curious about or never gotten started with Spacemacs. I’m going to cover the structure of the .spacemacs file and what you need to know about .emacs.d, plus some basic navigation. And some very specific advice.

Let’s start with what Spacemacs is. Spacemacs is not a emacs fork or anything like that, but rather a special way to configure it. It makes it much easier to get started than with the default .emacs.d config. Follow the official installation instructions and just hit enter on everything Spacemacs ask you about the first time you start and then give it some time. This will give you the standard setup.

The way spacemacs works is that it takes over the .emacs.d directory by cloning their git repository into .emacs.d. This has many advantages, one of them being that it is easy to update. If you need or want to add third party code or your own code, then you should add it to .emacs.d/private. It is ignored by the spacemacs git repo. That is everything you need to know about the .emacs.d directory for now.

Then you have the .spacemacs file. This is the configuration file. Spacemacs uses something called configuration layers to bundle functionality in a special way. They can be a little bit complicated to understand and get to work properly if you want to write their own. But they are totally awesome. Because they make sure that stuff don’t crash with each other more than necessary. And you typically don’t need to do a lot of “add this here, and then you modify this thing” type installation instructions. You just enable the layer and sometimes specify some variables to it, if it requires configuration.

A layer can be everything from adding support for PHP to a WakaTime client.

You .spacemacs file have the following functions:

  • dotspacemacs/layers

  • dotspacemacs/init

  • dotspacemacs/user-init

  • dotspacemacs/user-config

The layers function contains everything related to layers or emacs packages. If you want to install a package that is not a part of layer? Then you do it there. Want to enable a layer? You do it there. The init function on the other hand contains configuration settings for Spacemacs itself. Then you have user-init and user-config. Both of them contain your customisations, but most of it will probably end up in user-config; because user-init runs before your layers have been loaded while user-config runs after.

The first thing I would do is to read through the whole .spacemacs file. It contains all the settings and comments explaining them. Then I would read through the list of layers on the Spacemacs website. But only enable what you KNOW you will need. It isn’t hard to enable more layers later. And remember to enable to osx layer if you’re on a Mac.

Change what you need an restart Emacs.

There are three window management concepts you need to understand in order to get Emacs. You have the “frame” which is what you see on the screen. The frame can be split into different windows. And each window displays a buffer. But multiple windows can show the same buffer. A buffer can be everything from logs, to user interfaces to a file.

If you use the default Spacemacs settings, you will be using keybindings that are very close to those of VIM. I assume you have a basic understanding of how the VIM modes work. Make sure you are in Normal mode, Hit space. You will now se a small area pop up at the bottom of your screen. For example space ff will let you pick a file or folder to open.

There is one thing that is very important to understand about emacs. Everything you see and use in Emacs is a Emacs Lisp function. This means that if you don’t like how X works, you can always write your own custom function. If you hit space twice, you’ll enter M-x this will let you run ANY interactive function loaded as a part of your configuration. I use M-x all the time when I don’t remember the keyboard shortcut for something.

What I recommend if you want to get started with Spacemacs is to stop using your regular text editor for a week. Your productivity will be lower for a while, but it will improve a lot really fast.

Let’s begin with some basic keyboard commands:

You will often see commands like this C-a C-m, in Spacemacs that means SPC (space) a m. And M-x that means ESC x.

  • SPC ff : select folder, select file or create new file

  • SPC w : split window horizontal

  • SPC w : split window vertical

  • SPC fed : open config

  • SPC wd :remove window

  • SPC ss : list buffers

  • SPC TAB : change to last buffer

  • SPC bn : next buffer

  • SPC bp : previous buffer

  • SPC fs : save

  • SPC bd : close buffer

  • SPC feR : reload config

  • SPC pf : search for file

It is really hard in the beginning, but give it a few days and it will loosen up. Let me know if anything is unclear or if you have any questions.

#

20.02.2018 01:00

[@jack]1 was the emacs hugo “app” good?

#

20.02.2018 01:00

Hugo users: are there any plugin support?

#

20.02.2018 01:00

I survived

Cool string methods

20.02.2018 01:00

I was looking at new stuff coming in ES7 and ES8; you know, stuff that weirdos like me do. And I came over a very cool pair: padStart and padEnd. You can run it on any string and it will pad the end or the start with a string x times. It works like this:

Looks like a great option when you just want to add X of something either before or after a string.

#

19.02.2018 01:00

The latest in hospital fashion

Immutable.js

19.02.2018 01:00

There are some obvious advantages to using immutable data types. I personally think it is much easier to understand immutable code, and much easier to understand. The reason is that you replace data, and you omit the problem of two methods in a class trying to mutate the same thing. For example by incrementing a int twice or changing a boolean to the opposite twice.

The reason you can avoid this problem with a immutable data type is that you would instead of changing the data, send the initial data set to the function, make a copy and then return the mutated copy, that you replace the original data with.

Knowing that the result is always input + the code, and know that something else can’t be doing something weird in the background makes many thing a lot easier.

Immutable.js is one way to do Immutable data structures in JavaScript. You need a third party library because JavaScript don’t have real immutable data structures as a part of the language. I’m not using Immutable.js at the moment, but I have tested it out to a great extent in the past. And there are many great things about it. For example to test if two objects are the same by doing obj1 = obj2 is awesome.

But I have decided to not use it in any of my projects. Not because it’s bad or anything like that, but because I think it requires a little bit too much work. You have to use the Immutable Map and List objects instead of the native JavaScript ones. And you need to convert stuff between the native and immutable types all the time.

I agree on the basic premise. But I would have preferred something like a babel plugin, that let me use Immutable data structures without having to use a separate API.

Lightroom and previews

19.02.2018 01:00

I guess most beginners start out with the assumption that a “raw” file is just a fancy image file. But learn as they move on that it isn’t really a image or a picture file like a jpeg, but rather a huge collection of data that one can use to generate a image.

RAW files are big and powerful. Especially big.

Most people probably start out with a single lightroom library and then they shoot, import, remove the pictures you don’t want to keep and continue like that until their laptop drive is full. And then I assume many people do like me, move it to an external drive and start a new one. And continue that process for way too long. A better way to go about it is to add your external drive to a library on your internal one. One library is easier to navigate, and there aren’t really any good reasons to keep multiple ones.

If you import some raw files into lightroom as they are. And don’t do anything but adding the files. Then the experience isn’t the best, because then lighroom have to generate a JPEG preview every single time you open a new file. A better way to do this is to generate previews. Lightroom has three different previews, standard, 1:1 and smart. The standard sized preview is used when you look at a grid of photos and when you look at a single image (before you zoom in) and the 1:1 are used when you zoom in. While a smart preview is a small, lossy raw file that you can use to edit your photos (when the external drive is offline or if you want better performance).

I personally generate standard sized preivews for everything; they don’t take up much space; and makes everything a million times more enjoyable. And I also generate smart previews for everything because they don’t that up that much space and makes it more enjoyable to use Lightroom.

Then I also generate 1:1 Previews that I keep for a limited time, when I process images, and I re-generate them for selections of images when I work on them. Be aware: they take up a shit load of disk space, but makes it much faster when you zoom in and compare a lot of images. My workflow is that I discard them as soon as I don’t need them anymore.

#

17.02.2018 01:00

[@helgeg]1 where would I start if I was going to get into fancy keyboards?

#

17.02.2018 01:00

Cleaning my office, and found my iPhone 4s. Still my favourite.