Content AND Presentation

(Note to English-speaking readers: the links entitled Komentarze na tej stronie lead to comment pages.)

2016-06-27 Make yourself known – results

Now that the dust has settled, let me write a few words about the results of the Make yourself known contest.

Let me break the bad news first: I didn’t win. Not that I expected that (though I had a faint hope), but I have to say that I’m just a little bit disappointed. Here’s why. There was just short of 300 contestants at the beginning; it turned out that only 70 of them lasted to the end. I was one of them, so I may officially call myself a “finalist” (though “semifinals” would probably fit better). Out of these 70 people, sixteen were chosen for the finals – and here’s where my (slight) disappointment comes from: I was not one of them.

But there are plenty of good news. One of them is that my friend ended up third. Nice, and congratulations! (Of course, my congratulations go to other winners, too!) Other than that, I learned quite a lot, and gained some confidence. I did put the Logeox project aside for now, since I have an awful lot of other work, but it is possible that I’ll come back to it some day.

Also, I think it is interesting to ponder a bit about the reasons I didn’t win. Not because I feel a strong pressure to win next time (if there’s next time, and I hope so), but because I think there’s a lesson to be learned here. Since the contest was (at least partially) a popularity contest, I guess my mistake was that I didn’t participate more in the community. As I mentioned before, I think it’s a shame, and I do regret it – not only because it probably decreased my chances to win (and they were not that impressive to start with anyway), but because it is definitely a lost opportunity. So, here’s my plan regarding the contest now: I’d like to revisit at least some of the blogs, learn from them, leave some comments and maybe meet interesting people (if only virtually).

Once again, congratulations to the winners, and thanks for the great event!

CategoryEnglish, CategoryBlog, CategoryMakeYourselfKnown

Comments on this page

2016-06-20 Easy Javascript logging

I’ve been doing some JavaScript coding recently. Before you run off screaming, let me tell you that JavaScript is not that bad. Yes, it has C-like, unlispy syntax, but at its heart it is quite a nice language. Today, though, I didn’t want to write about JS in general, but about one small detail. While debugging JavaScript code, it is often useful to sprinkle console.log statements in your code. Also, if you want to check the value of some more complicated variable, you need to JSON.stringify it first. Of course, writing repetitive pieces of code is not what an Emacs user would like to do, so I hacked this:

(defun js-insert-console-log ()
  "Insert a console.log statement in the line below.
If region is active, treat it as the variable to log."
  (let ((variable (if (use-region-p)
		      (buffer-substring-no-properties (region-beginning)
    (move-end-of-line 1)
    (if variable
	   (format "console.log(\"%s: \" + JSON.stringify(%s, null, '\\t'));"
      (insert "console.log();")
      (backward-char 2))))

Note that this is really only a quick hack – it doesn’t use js2-mode’s JS parsing capabilities, for instance (I’d like to understand them some day, but I’d have to learn about EIEIO first). After having used it quite intensely for a few days now, though, I haven’t noticed any problems.

(Of course, it is only a poor substitute for real debugging; this SO answer gives a few possibilities. I’ll look into this in some Free Time™.)

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryJavaScript

Comments on this page

2016-06-13 Displaying pdfs on the right

Some time ago I decided that I’ll give PDF tools a shot.

Wow. Just wow. Never going back to Evince. (Well, almost never – Evince does have one or two options not present in PDF Tools, but I hardly ever use them). If you are an Emacs user on GNU+Linux, I strongly advice you to try PDF Tools out. Especially if you do a lot of LaTeX work in AUCTeX (like I do) and/or if you need to read or create PDF annotations (highlighting and/or notes) – it’s really great. (I did once experience some problems with said annotations, though.) I was a bit afraid about the efficiency – but man, it’s really fast! A great piece of work indeed.

I have a few problems with it, though. The biggest one is that C-M-v (scroll-other-window) won’t switch to next page of the pdf. (Emacs’ doc-view has the same problem, and it seems that it’s not trivial to change, at least not without advice). Another one is that sometimes, when I zoom in a bit and do something, my carefully found place in the pdf is gone, and some other place is shown. But none of these is a deal-breaker.

One thing I found really annoying (though it’s not related to PDF Tools – again, doc-view has the same problem): when I pressed C-c C-v (TeX-view), the pdf was shown in a window below the current one. Since most of my documents are in “portrait” mode, this doesn’t make sense at all – I’d very much prefer if the window with the pdf was shown to the right of the current one.

OTOH, I would not want everything to pop up to the right. I use a laptop with a 14” screen, which is just a tad too small for that to be comfortable. (And I’m totally not accustomed to such a behavior.)

Of course, the solution is known already: display-buffer-alist. However, while we’re at it, there is one more thing to take care of: I don’t want the window containing the pdf to be half the screen wide. It doesn’t really make sense, either. The aspect ratio of my screen is 16:9, which means that a horizontal split divides the main window into two almost square halves. OTOH, I use almost exclusively the A4 paper size, whose aspect ratio is √2:1. (Those strange Americans who use those strange paper sizes might want to adjust for that, although even they are not strange enough to use square paper for most of their documents.) This means that by dividing the window in the middle, I waste a lot of screen real estate.

It turns out that making Emacs split windows in the desired proportion is not a trivial task (see here and here for some pointers). In this case, however, it’s not a big problem: I can find out the correct value of the argument for split-window-right by trial and error, and this is exactly what I did.

All in all, let the code speak for itself. It is not very elegant in that I just copy-pasted the split-window-sensibly function and made the changes I needed, but I don’t see how I could achieve my goal in a more elegant way with, say, advice, so who cares. If you want different settings, just play around with the two variables introduced below.

Finally, notice that my previous version of the regex for buffers displayed on the right, which was just "\\.pdf$", does not work if there are two pdfs with the same name, but different directories displayed at the same time, since by default Emacs appends a string of the form <directory> to the end of the buffer name then. Pretty rare, I’d argue, but it actually happened to me, and it was not obvious at first what was going on!

(defvar pdf-minimal-width 72
  "Minimal width of a window displaying a pdf.
If an integer, number of columns.  If a float, fraction of the
original window.")

(defvar pdf-split-width-threshold 120
  "Minimum width a window should have to split it horizontally
for displaying a pdf in the right.")

(defun pdf-split-window-sensibly (&optional window)
  "A version of `split-window-sensibly' for pdfs.
It prefers splitting horizontally, and takes `pdf-minimal-width'
into account."
  (let ((window (or window (selected-window)))
	(width (- (if (integerp pdf-minimal-width)
		    (round (* pdf-minimal-width (window-width window)))))))
    (or (and (window-splittable-p window t)
	     ;; Split window horizontally.
	     (with-selected-window window
	       (split-window-right width)))
	(and (window-splittable-p window)
	     ;; Split window vertically.
	     (with-selected-window window
	(and (eq window (frame-root-window (window-frame window)))
	     (not (window-minibuffer-p window))
	     ;; If WINDOW is the only window on its frame and is not the
	     ;; minibuffer window, try to split it vertically disregarding
	     ;; the value of `split-height-threshold'.
	     (let ((split-height-threshold 0))
	       (when (window-splittable-p window)
		 (with-selected-window window

(defun display-buffer-pop-up-window-pdf-split-horizontally (buffer alist)
  "Call `display-buffer-pop-up-window', using `pdf-split-window-sensibly'
when needed."
  (let ((split-height-threshold nil)
	(split-width-threshold pdf-split-width-threshold)
	(split-window-preferred-function #'pdf-split-window-sensibly))
    (display-buffer-pop-up-window buffer alist)))

(add-to-list 'display-buffer-alist '("\\.pdf\\(<[^>]+>\\)?$" . (display-buffer-pop-up-window-pdf-split-horizontally)))

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryTeX

Comments on this page


(Więcej means More in Polish; click it to see older entries.)

CategoryEnglish, CategoryBlog