__________________

                           EMACS AND GOPHER
                          __________________


Table of Contents
_________________

1. Browsing
. 1. Gopher browser in Emacs
. 2. Using Lynx in a terminal buffer
2. Creating gopher optimized documents
. 1. Org-mode
. 2. Org-mode header
. 3. Germanic Umlauts
. 4. Justify Text
3. Gophermaps





1 Browsing
==========

1.1 Gopher browser in Emacs
~~~~~~~~~~~~~~~~~~~~~~~~~~

 To browse  the gopher space I  use a gopher client  for emacs called
 elpher[1]. It's very  stable and easy to  use but a bit  on the slow
 side presumably owed to its implementation in elisp. Loading the sdf
 user directory  [2] takes over  10 seconds (lynx takes  ~2). Another
 drawback is  that is requires emacs  version 26 which may  not be in
 your repository.


1.2 Using Lynx in a terminal buffer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 Another option  is to run the  lynx browser[3] in a  terminal window
 inside  emacs. Emacs  offers  four(?)  terminals *shell*,  *eshell*,
 *term*  and  *ansi-term*.  I  prefer   to  use  the  last  one  (M-x
 ansi-term). Now I can start lynx inside the terminal. If you want to
 copy  something from  lynx to  another buffer  you have  to activate
 term-line-mode (C-c C-j). Now you can move the cursor around freely.
 To switch back to term-char-mode press C-c C-k. This method is a bit
 wonky but it works.


2 Creating gopher optimized documents
=====================================

2.1 Org-mode
~~~~~~~~~~~

 I write  all my  articles in  emacs org-mode[4].  If you  don't know
 org-mode already you seriosly should give it a try! It's basically a
 way  to structure  documents in  plain-text. Even  if you  don't use
 emacs  you can  look at  an org-file  and read  its content.  A very
 powerful feature  of org-mode  is the exporter.  By default  you can
 export to  text, html, LaTex and  some other formats. When  I create
 documents for  gopher I usually export  to an ASCII file  (C-c C-e t
 a). You  can also export to  UTF8 which is prettier  but some gopher
 clients only support ASCII.


2.2 Org-mode header
~~~~~~~~~~~~~~~~~~

 You  can give  org-mode  some  export options[5].  The  head of  the
 org-document that was exported to this very file looks like this.

 ,----
 | #+OPTIONS: author:nil toc:t
 | #+LANGUAGE: en
 | #+TITLE: Emacs and gopher
 `----


2.3 Germanic Umlauts
~~~~~~~~~~~~~~~~~~~

 Because Germanic umlauts  are not part of ASCII I  have to translate
 them  for my  German texts.  I wrote  an elisp  function to  do this
 automatically.

 ,----
 | (defun translate-gopher-special ()
 |   (interactive)
 |   (let ((case-fold-search nil)
 |         (trans-list
 |          (list '("ä" . "ae")
 |                '("ö" . "oe")
 |                '("ü" . "ue")
 |                '("Ä" . "Ae")
 |                '("Ö" . "Oe")
 |                '("Ü" . "Ue")
 |                '("ß" . "ss")
 |                '("„" . "\"")
 |                '("“" . "\""))))
 |     (mapc (lambda (x)
 |             (goto-char (point-min))
 |             (while (search-forward (car x) nil t)
 |               (replace-match (cdr x) t)))
 |           trans-list)))
 `----

 In this  file I did not  run the code  above so if it  isn't display
 correctly your client only supports the ASCII charset.


2.4 Justify Text
~~~~~~~~~~~~~~~

 In emacs  there is a  neat function  to fill and  justify paragraphs
 (C-0 M-q). From the emacs documentation:

       The command M-q (fill-paragraph)  fills the current paragraph.
       It  redistributes the  line breaks  within the  paragraph, and
       deletes any  excess space and tab  characters occurring within
       the paragraph,  in such a  way that  the lines end  up fitting
       within a  certain maximum width.  [...] A numeric  argument to
       M-q tells it  to justify the text as well  as filling it. This
       means that extra spaces are  inserted to make the right margin
       line up exactly at the fill column.[6]

 The  problem is  after exporting  I have  to justify  the paragraphs
 again because the exporter ignores superfluous blanks. The following
 script  justifies  only  indented  paragraphs  that  start  with  an
 alphanumerical symbol.  Therefore this  does not apply  to headings,
 lists, code blocks, etc.

 ,----
 | (defun gopher-justify ()
 |   (interactive)
 |   (beginning-of-buffer)
 |   (forward-line 4) ;; skip title
 |   (while (not (eobp))
 |     (progn
 |       (when (re-search-forward "^[[:blank:]]+[[:alnum:]]" nil t nil)
 |         (fill-paragraph 1 nil))
 |       (forward-paragraph 1))))
 |
 `----

 It's not fool proof but most of  the time it works. In some places I
 have to insert an  extra blank line in my org-file  so that the next
 text block doesn't get justified.

 This was the final step. Now the document is ready for publishing.


3 Gophermaps
============

 As I have completly disabled the use of tabs in my init file I start
 emacs without loading any user settings to edit gophermaps:

 ,----
 | emacs -q /path/to/gopermap
 `----

 A very useful emacs  feature regarding gophermaps is whitespace-mode
 (M-x whitespace-mode) which makes whitespace characters visible.



Footnotes
_________

[1] gopher://thelambdalab.xyz/1/projects/elpher/

[2] gopher://sdf.org/1/maps

[3] gopher://gopherpedia.com:70/0/Lynx%20(web%20browser)

[4] <https://orgmode.org/>

[5] <https://orgmode.org/manual/Export-Settings.html>

[6]
<https://www.gnu.org/software/emacs/manual/html_node/emacs/Fill-Commands.html>