Thursday, 28 January 2016

Spacemacs

Introduction

Press space to explore the interactive list of carefully-chosen key bindings.
You can also press the home buffer’s [?] button for some great first key bindings to try

Common keys

Help:
space f help define function - fuzzy search for a function and find out how to use it
space k help define key - insert any key sequence and find out what it’s bound to

Windows:
space v split screen to the right
space l jump to window at right
space h jump to window at left
space space show a letter on each window which you can press to jump to

Buffers:
space tab switch to last buffer
space b show list of open buffers
space d kills the current buffer
space s switch to scratch buffer (analogous to new file)
space s save file (if it’s the scratch buffer it will prompt you for a name)

Open a file:
space f opens the file navigator
ctrl l jumps into a folder
ctrl h jumps out of a folder
enter opens the selected file into a new buffer
to create a new file - open the scratch buffer (space b s) and when ready to save (space f s)

Projects:
projects are typically defined by a source control marker, such as a .git folder, or can be manually created by defining a .projectile file
space f opens the project navigator
space p switch to another project
enter then opens the project navigator for that project

Searching:
space / searches through a whole project (using the tool specified by dotspacemacs-search-tools)
spaces searches within a file (helm swoop)
ctrl j move down in the seach results
ctrl k move up in the seach results
space l shows a list of all the functions on the current file (requires the semantic layer)
space space shows a prompt for a char, and then shows all locations of words which begin with that char. Press the appropriate key to jump to that location.
space` jump back to previous mark (consider using ctrlo instead)

Compilation:
space C build
space r repeat last build command

Text selection:
space v select region
v expand region
V contract region

Help:
space d describe
f functions
v variables
k key-bindings
space h open help documentation

Completion:
requires dotspacemacs-configuration-layers auto-completion to be enabled
ctrl l paste selected completion
ctrl / fuzzy search
alt / auto-complete selected function template

Workspaces:
requires dotspacemacs-configuration-layers eyebrowse to be enabled
space 0..9 switch to or create workspace
t switch to next workspace
g T switch to previous workspace
space c close current workspace

Editing:
space; toggle comment (if region currently selected - comments that, otherwise enters toggle comment mode)
p comment paragraph
i comment indent region

Moving:
space j jump in buffer

Wednesday, 27 January 2016

emacs 24.5 on Ubuntu and spacemacs

Spacemacs on on Ubuntu 14.04

Build emacs-24.5

Install git and build-essential:

$ sudo apt-get install -y git build-essential

Install emacs24 build dependencies

$ sudo apt-get build-dep emacs24

Download the source for the version of emacs you want from the emacs ftp site

Unpack the source into a directory where you’re going to build it

$ cd /tmp
$ mv ~/Downloads/emacs-24.5.tar.xz .
$ tar -xf emacs-24.5.tar.xz 
$ cd emacs-24.5

Configure and build it

$ ./configure
$ make -j4
$ sudo make install

Install spacemacs

Move any existing emacs configuration to backup

$ mv ~/.emacs.d ~/.emacs.d.bak

Clone the spacemacs repo:

$ git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d

Launch and it will install it’s required packages

Monday, 14 December 2015

emacs lisp

setq

set quoted value

(setq SYMBOL VALUE)
(setq global-mark-ring-max 50000)

load

executes a file of lisp code.
first tries to find FILE.elc then FILE.el then FILE

(load FILE NOERROR=Nil NOMESSAGE=Nil NOSUFFIX=Nil MUST-SUFFIX=Nil)
(load "$HOME/.emacs.d/module")

require

(require FEATURE FILENAME=Nil NOERROR=Nil)
(require 'volatile-highlights)

add-to-list

(add-to-list VARIABLE VALUE)
(add-to-list 'load-path "~/.emacs.d/personal")

add-hook

prepends a function to the hooked event

(add-hook HOOK FUNCTION APPEND=Nil LOCAL=Nil)
(add-hook 'prog-mode-hook 'linum-mode)

global-set-key

(global-set-key KEY COMMAND)
(global-set-key (kbd "C-x C-b") 'ibuffer)

define-key

(define-key KEYMAP KEY DEF)
(define-key dired-mode-map (kbd "e") 'wdired-change-to-wdired-mode)

defalias

define alias

(defalias SYMBOL DEFINITION DOCSTRING=Nil)
(defalias 'eb 'eval-buffer)

mapc

call function on every element in sequence

(mapc FUNCTION SEQUENCE)
(mapc 'load (directory-files "~/.emacs.d/custom" t ".*\.el"))

defun

define function

(defun NAME ARGLIST DOCSTRING=Nil DECL=Nil BODY)
(defun demo ()
    (message "Hello World" number string))

Saturday, 28 November 2015

emacs motion

emacs motion

C-f: forward one char
C-b: backward one char
C-p: previous line
C-n: next line

C-a: beginning of line
C-e: end of line
M-f: forward one word
M-b: backward one word

C-v: forward one screen
M-v: backward one screen
M-a: beginning of sentence
M-e: end of sentence
C-l: center the screen
M-r: cycle point through top, middle and bottom of the screen
M-<: jump to the top of the buffer
M->: jump to the end of the buffer
M-g c: jump to the nth character
M-g l: jump to the nth line

C-M-f: forward over balanced expression (eg: braces in C++ code)
C-M-b: backward over balanced expression
C-M-k: delete balanced expression
C-M-<SPC> or C-M-@: mark balanced expression

emacs ibuffer

ibuffer

In ~/.emacs.d/init.el:

;; replace `list-buffers` with `ibuffer`
(global-set-key (kbd "C-x C-b") 'ibuffer)

Open ibuffer by C-x C-b

Create filters:

/m: filter by a major mode
/n: filter by buffer name.
/c: filter by buffer content.
/f: filter by filename
/>: filter by buffer size
/<: filter by buffer size
//: remove all filters in effect

Filtered groups:

/g: create a filter group from filters
TAB: move to next filter group
M-p: move to previous filter group
/\: remove all active filter groups
/S: save the current groups with a name
/R: restore previously saved groups
/X: delete previously saved groups

Every time you open a file which matches a filter it will appear under the group

o on a file will open that file and switch focus to it
C-o on a file will open that file and leave focus in ibuffer
C-x o switches focus to the other window

Saturday, 7 November 2015

Create a bootable USB from an ISO using dd on the Linux command line

Install syslinux, a suite of utilities which ensures the iso image is in SYSLINUX format rather than ISOLINUX

    $ sudo apt-get install syslinux

Convert the iso image to SYSLINUX format

    $ isohybrid /path/image.iso 

Locate the USB device 

    $ lsblk
    sdb         8:16   1   3.8G  0 disk 
    └─sdb1      8:17   1   3.8G  0 part /media/user/usb_disk

Unmount the USB device

    $ sudo umount /dev/sdb1

Ensure it is indeed unmounted

    $ lsblk
    sdb         8:16   1   3.8G  0 disk 
    └─sdb1      8:17   1   3.8G  0 part 

Copy the ISO image onto the USB deisk

    $ sudo dd if=/path/image.iso of=/dev/sdb1

Wednesday, 28 October 2015

Qt: Updating styles based on dynamic properties

#include <QApplication>
#include <QMainWindow>
#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QStyle>
#include <QDebug>

class App : public QObject
{
    Q_OBJECT
public:
    enum Alert
    {
        None,
        Warning,
        Critical
    };
    Q_ENUM(Alert);

    App(int argc, char** argv)
        : app(argc, argv)
    {}

    int exec()
    {
        window.setCentralWidget(&main);

        label.setText("hello world");
        label.setProperty("alert", QVariant::fromValue(None));

        button.setText("alert");

        QObject::connect(&button, &QPushButton::clicked, [this]()
            {
                label.setProperty("alert", QVariant::fromValue(Critical));
                label.setProperty("foo",   false);

                label.style()->unpolish(&label);
                label.style()->polish(&label);
                label.update();
            });

        layout.addWidget(&label);
        layout.addWidget(&button);
        main.setLayout(&layout);

        app.setStyleSheet(R"(
            QLabel[alert="None"]                { color: green; } 
            QLabel[alert="Warning"]             { color: blue;  }
            QLabel[alert="Critical"][foo=true]  { color: red;     }
            QLabel[alert="Critical"][foo=false] { color: magenta; }
        )");

        window.show();
        return app.exec();
    }

    QApplication app;
    QMainWindow  window;
    QWidget      main;
    QLabel       label;
    QPushButton  button;
    QVBoxLayout  layout;
};

int main(int argc, char** argv)
{
    return App(argc, argv).exec();

}