Emacs customizations for julia-mode

2017/08/28 julia emacs

I find the following customizations very useful for editing Julia code in Emacs. Add them to julia-mode-hook, eg

(defun customize-julia-mode ()
  "Customize julia-mode."
  ;; my customizations go here

(add-hook 'julia-mode-hook 'customize-julia-mode)

Highlight FIXME/TODO/…

When I just want to note something in a comment for future reference, I prefer to have certain words highlighted. You can use something like this:

(font-lock-add-keywords nil
                        1 font-lock-warning-face t)))

This is what it looks like:

            if any(ifail .!= 0)
                # TODO: better error message / type
                error("failed to converge eigenvectors:\n$(nonzeros(ifail))")

Highlight symbols


(require 'highlight-symbol)

add a hook for

(local-set-key [(control ?c) ?s] 'highlight-symbol-at-point)
(local-set-key [(control ?c) ?n] 'highlight-symbol-next)
(local-set-key [(control ?c) ?p] 'highlight-symbol-prev)

This highlights symbols with C-c s:

function issymmetric(A::AbstractMatrix)
    indsm, indsn = indices(A)
    if indsm != indsn
        return false
    for i = first(indsn):last(indsn), j = (i):last(indsn)
        if A[i,j] != transpose(A[j,i])
            return false
    return true

Fill docstrings

This is useful if you want to use M-q on docstrings.

(defun julia-fill-string ()
  "Fill a docstring, preserving newlines before and after triple quotation marks."
  (if (and transient-mark-mode mark-active)
      (fill-region (region-beginning) (region-end) nil t)
    (cl-flet ((fill-if-string ()
                              (when (or (looking-at (rx "\"\"\""
                                                         (*? (or (not (any "\\"))
                                                                 (seq "\\" anything))))
                                        (looking-at (rx "\""
                                                         (*? (or (not (any "\\"))
                                                                 (seq "\\" anything))))
                                (let ((start (match-beginning 1))
                                      (end (match-end 1)))
                                  ;; (ess-blink-region start end)
                                  (fill-region start end nil nil nil)))))
        (let ((s (syntax-ppss)))
          (when (fourth s) (goto-char (ninth s))))


(local-set-key (kbd "M-q") 'julia-fill-string)

to the mode hook.

Highlight things after column 80

I add this to the mode hook:

(set-fill-column 80)

I also use whitespace globally:

(require 'whitespace)
(setq whitespace-style '(face empty tabs lines-tail trailing))
(global-whitespace-mode t)

This is what it looks like:

    QR{T,S}(factors::AbstractMatrix{T}, τ::Vector{T}) where {T,S<:AbstractMatrix} = new(factors, τ)
QR(factors::AbstractMatrix{T}, τ::Vector{T}) where {T} = QR{T,typeof(factors)}(factors, τ)

Hungry delete-mode

Add this to the mode hook:


and then backspace and delete will remove all whitespace near the point in the relevant direction.

In case you are wondering, the theme is alect-light.

site not optimized for small screens, math may break