<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title>Mohammed Sadiq's blog</title>
  <link rel="self" href="https://www.sadiqpk.org/blog.xml"/>
  <link href="https://www.sadiqpk.org/"/>
  <updated>2026-11-09T13:43:25+00:00</updated>
  <author>
    <name>Mohammed Sadiq</name>
  </author>
  <id>https://www.sadiqpk.org/blog/</id>

  <entry>
    <title> Blogging with Emacs org-mode</title>
    <link href="blog/2018/08/08/blogging-with-org-mode.html"/>
    <id>https://www.sadiqpk.org/blog/2018/08/08/blogging-with-org-mode.html</id>
    <published>2018-08-08T00:05:00+05:30</published>
    <updated>2018-08-08T00:05:00+05:30</updated>
    <content type="html"><![CDATA[<div id="content" class="content">
<p>
<span class="info Note:">All pages of this website has been designed in org-mode. Not just this blog. The <a href="https://gitlab.com/sadiq/sadiq.gitlab.io">repository</a> contain source code for the complete website.  </span>
</p>
<div id="outline-container-orgb72f4f2" class="outline-2">
<h2 id="orgb72f4f2">Introduction</h2>
<div class="outline-text-2" id="text-orgb72f4f2">
<p>
For about a year, I have been trying to find a suitable workflow
to blog using Emacs org-mode.  My idea was to put all
articles (posts) in a single org file, which failed miserably
for the following reasons:
</p>

<ul class="org-ul">
<li>The default org-mode html export is designed to work on separate
files.  So single file org export requires custom code which I
don't want to write.</li>
<li>I wish to link to the source org file from each html article, which
is not possible if every article is written in a single file.</li>
</ul>

<p>
Last year, I did write around 500 lines of code, which worked.
Pretty much all of them were unmaintainable hacks.  A few days back, I
gave it a try again.  This time, with a different design:
</p>

<ul class="org-ul">
<li>Each article is written in separate org files, with dated directory names.
Eg.: A <code>hello-world.org</code> file in <code>2018/08/08</code> dir for <i>Hello World</i> article.</li>
<li>Manually created blog index and atom feeds so that I don't have to wait
another year to <a href="https://xkcd.com/974/">pass the salt</a>.</li>
</ul>

<p>
For the impatient, get the source code <a href="https://gitlab.com/sadiq/sadiq.gitlab.io">here</a>.  The complete source code
(including the sass design style sheets) are released into public domain
(CC0).  Feel free to use it the way you like.  If you wish to attribute me,
link to my website <a href="https://www.sadiqpk.org">www.sadiqpk.org</a>.
</p>
</div>
</div>
<div id="outline-container-org77ac3d5" class="outline-2">
<h2 id="org77ac3d5">The work flow</h2>
<div class="outline-text-2" id="text-org77ac3d5">
<p>
The following is a barebone example on using Emacs org-mode for blogging.
For a practically usable code, see the <a href="https://gitlab.com/sadiq/sadiq.gitlab.io">source</a> of this website.
</p>

<ul class="org-ul">
<li>Create a directory for saving your website source, say <code>~/web/src/</code>.</li>
<li><p>
Create an org file with your favorite article, say
<code>~/web/src/blog/2018/08/08/hello-world.org</code> with some content.
</p>

<div class="org-src-container">
<pre class="src src-org"><span class="org-org-document-info-keyword">#+author:</span> <span class="org-org-document-info">Alice
</span><span class="org-org-document-info-keyword">#+title:</span> <span class="org-org-document-title">Hello world
</span><span class="org-org-document-info-keyword">#+date:</span> <span class="org-org-document-info">&lt;2018-08-08 Wed&gt;
</span><span class="org-org-meta-line">#+keywords: hello, world, emacs, blog</span>
<span class="org-org-meta-line">#+description: Hello world</span>

I like <span class="org-org-code">~org-mode~</span>.
</pre>
</div></li>

<li><p>
Create the project configuration and save it to some file,
say <code>~/web/src/my-web.el</code>.
</p>

<div class="org-src-container">
<pre class="src src-elisp">(<span class="org-keyword">require</span> '<span class="org-constant">org</span>)
(<span class="org-keyword">setq</span>
 org-publish-project-alist
 '((<span class="org-string">"blog"</span>
    <span class="org-builtin">:base-directory</span> <span class="org-string">"src/blog"</span>
    <span class="org-builtin">:base-extension</span> <span class="org-string">"org"</span>
    <span class="org-builtin">:publishing-directory</span> <span class="org-string">"public/blog"</span>
    <span class="org-builtin">:recursive</span> t
    <span class="org-builtin">:publishing-function</span> org-html-publish-to-html)

   (<span class="org-string">"website"</span>
    <span class="org-builtin">:components</span> (<span class="org-string">"blog"</span>))))
</pre>
</div></li>
</ul>

<p>
The directory structure will look like this:
</p>

<div class="org-src-container">
<pre class="src src-sh">~/web/src$ tree
.
&#9500;&#9472;&#9472; blog
&#9474;&#160;&#160; &#9492;&#9472;&#9472; 2018
&#9474;&#160;&#160;     &#9492;&#9472;&#9472; 08
&#9474;&#160;&#160;         &#9492;&#9472;&#9472; 08
&#9474;&#160;&#160;             &#9492;&#9472;&#9472; hello-world.org
&#9492;&#9472;&#9472; my-web.el

4 directories, 2 files
</pre>
</div>

<ul class="org-ul">
<li><p>
Now we can publish the project to get the static HTML pages:
</p>

<div class="org-src-container">
<pre class="src src-sh">~/web$ emacs --batch -q -l src/my-web.el -f org-publish-all
</pre>
</div></li>
</ul>

<p>
That's it.  The <code>hello-world.org</code> will now be exported as
<code>~/web/public/blog/2018/08/08/hello-world.html</code>.
</p>
</div>
</div>
<div id="outline-container-org42f8c40" class="outline-2">
<h2 id="org42f8c40">Conclusion</h2>
<div class="outline-text-2" id="text-org42f8c40">
<p>
This is an overly simplified example.  To see how the
<a href="https://www.sadiqpk.org/blog/2018/08/08/hello-world.html">Hello World</a> blog post is written, see its <a href="https://gitlab.com/sadiq/sadiq.gitlab.io/raw/master/src/blog/2018/08/08/hello-world.org">source</a>.  Also
see the project <a href="https://gitlab.com/sadiq/sadiq.gitlab.io/blob/master/src/my-web.el">configuration file</a> and atom feed generation
<a href="https://gitlab.com/sadiq/sadiq.gitlab.io/blob/master/src/blog-atom.sh">script</a>.
</p>


<p>
<b>Update:</b> See <a href="https://news.ycombinator.com/item?id=17714815">Hacker News discussion</a>.
</p>
</div>
</div>
</div>]]></content>
  </entry>

  <entry>
    <title> Hello World</title>
    <link href="blog/2018/08/08/hello-world.html"/>
    <id>https://www.sadiqpk.org/blog/2018/08/08/hello-world.html</id>
    <published>2018-08-08T00:01:00+05:30</published>
    <updated>2020-05-10T15:47:00+05:30</updated>
    <content type="html"><![CDATA[<div id="content" class="content">
<p>
<span class="info Note:"> This is a demo page to test the features of this blog. Don’t expect much here.  </span>
</p>

<p>
In the software world, everything begins with <code>Hello World</code>.  This is
the beginning of my blog.  Let’s see how this will go.  This page stands
to test the features of this blog.
</p>

<p>
This website has been completely designed using GNU Emacs.  The static
web pages are written in Emacs org-mode and exported to HTML.
If you are not yet a <a href="https://www.gnu.org/software/emacs/">GNU Emacs</a> user, give it a try.  It’s worth learning.
If you are familiar with vim, see <a href="http://spacemacs.org">Spacemacs</a>.  You shall feel home.
</p>

<p>
To begin with, let’s see how code blocks in different language be handled.
This should be pretty smooth, and cool .
</p>
<div id="outline-container-orgf8ad1f3" class="outline-2">
<h2 id="orgf8ad1f3"><code>Hello World</code></h2>
<div class="outline-text-2" id="text-orgf8ad1f3">
<p>
How about showing some real content?  Have a look at a few
examples below.
</p>
</div>
<div id="outline-container-org38f0ece" class="outline-3">
<h3 id="org38f0ece">C Programming</h3>
<div class="outline-text-3" id="text-org38f0ece">
<p>
Let’s begin with <code>Hello World</code> in C Programming.
</p>

<div class="org-src-container">
<pre class="src src-c"><span class="org-preprocessor">#include</span> <span class="org-string">&lt;stdio.h&gt;</span>

<span class="org-type">int</span>
<span class="org-function-name">main</span> (<span class="org-type">void</span>)
{
  printf (<span class="org-string">"Hello World!\n"</span>);

  <span class="org-comment-delimiter">/* </span><span class="org-comment">Implicit in c99+</span><span class="org-comment-delimiter"> */</span>
  <span class="org-keyword">return</span> 0;
}
</pre>
</div>

<p>
Save the above code into <code>hello.c</code>, then compile and run.
</p>
<div class="org-src-container">
<pre class="src src-sh"><span class="org-comment-delimiter"># </span><span class="org-comment">Compile and run
</span>gcc hello.c -o hello &amp;&amp; ./hello

<span class="org-comment-delimiter"># </span><span class="org-comment">An alternate way for the same.  If you are
</span><span class="org-comment-delimiter"># </span><span class="org-comment">wondering, no, you don't need any Makefile.
</span>make hello &amp;&amp; ./hello
</pre>
</div>
</div>
</div>
<div id="outline-container-org8dca69c" class="outline-3">
<h3 id="org8dca69c">Emacs lisp</h3>
<div class="outline-text-3" id="text-org8dca69c">
<p>
Now let’s try this in elisp.  The code below will print “Hello World!”
to the echo area.  To run the program, write the code in GNU Emacs,
put the cursor at end of the paren and press <span class="key"><span>C-x C-e</span></span> .
</p>

<div class="org-src-container">
<pre class="src src-elisp">(message <span class="org-string">"Hello World!"</span>)
<span class="org-comment-delimiter">;; </span><span class="org-comment">Put the cursor here  ^</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-gtk-c" class="outline-3">
<h3 id="gtk-c">GUI using GTK and C</h3>
<div class="outline-text-3" id="text-gtk-c">
<p>
The following example shows a window with a “Hello World!” label.
The code will work with GTK3.
</p>

<div class="org-src-container">
<pre class="src src-c"><span class="org-comment-delimiter">/*</span><span class="org-comment">
 * Hello world with GTK3 in C
 *
 * By Mohammed Sadiq &lt;sadiq [at] sadiqpk [d0t] org&gt;
 * Date: 2020 May 10
 * License: None, Public domain (CC0)
 *
 * Compile:
 *   gcc hello.c $(pkg-config --cflags --libs gtk+-3.0) -o hello
 *
 * Run:
 *   ./hello
</span><span class="org-comment-delimiter"> */</span>

<span class="org-preprocessor">#include</span> <span class="org-string">&lt;gtk/gtk.h&gt;</span>

<span class="org-keyword">static</span> <span class="org-type">void</span>
<span class="org-function-name">activate_cb</span> (<span class="org-type">GtkApplication</span> *<span class="org-variable-name">app</span>,
             <span class="org-type">gpointer</span>        <span class="org-variable-name">user_data</span>)
{
  <span class="org-type">GtkWindow</span> *<span class="org-variable-name">window</span>;
  <span class="org-type">GtkWidget</span> *<span class="org-variable-name">label</span>;

  window = GTK_WINDOW (gtk_application_window_new (app));
  gtk_window_set_title (window, <span class="org-string">"Hello World!"</span>);
  gtk_window_set_default_size (window, 400, 300);

  label = gtk_label_new (<span class="org-string">"Hello World!"</span>);
  gtk_container_add (GTK_CONTAINER (window), label);
  gtk_widget_show (label);

  gtk_window_present (window);
}

<span class="org-type">int</span>
<span class="org-function-name">main</span> (<span class="org-type">int</span>    <span class="org-variable-name">argc</span>,
      <span class="org-type">char</span> **<span class="org-variable-name">argv</span>)
{
  g_autoptr(GtkApplication) app = <span class="org-constant">NULL</span>;

  app = gtk_application_new (<span class="org-string">"org.sadiqpk.example"</span>, 0);
  g_signal_connect (app, <span class="org-string">"activate"</span>, G_CALLBACK (activate_cb), <span class="org-constant">NULL</span>);

  <span class="org-keyword">return</span> g_application_run (G_APPLICATION (app), argc, argv);
}
</pre>
</div>

<p>
The same in GTK4:
</p>

<div class="org-src-container">
<pre class="src src-c"><span class="org-comment-delimiter">/*</span><span class="org-comment">
 * Hello world with GTK4 in C
 *
 * By Mohammed Sadiq &lt;sadiq [at] sadiqpk [d0t] org&gt;
 * Date: 2020 May 10
 * License: None, Public domain (CC0)
 *
 * Compile:
 *   gcc hello.c $(pkg-config --cflags --libs gtk4) -o hello
 *
 * Run:
 *   ./hello
</span><span class="org-comment-delimiter"> */</span>

<span class="org-preprocessor">#include</span> <span class="org-string">&lt;gtk/gtk.h&gt;</span>

<span class="org-keyword">static</span> <span class="org-type">void</span>
<span class="org-function-name">activate_cb</span> (<span class="org-type">GtkApplication</span> *<span class="org-variable-name">app</span>,
             <span class="org-type">gpointer</span>        <span class="org-variable-name">user_data</span>)
{
  <span class="org-type">GtkWindow</span> *<span class="org-variable-name">window</span>;
  <span class="org-type">GtkWidget</span> *<span class="org-variable-name">label</span>;

  window = GTK_WINDOW (gtk_application_window_new (app));
  gtk_window_set_title (window, <span class="org-string">"Hello World!"</span>);
  gtk_window_set_default_size (window, 400, 300);

  label = gtk_label_new (<span class="org-string">"Hello World!"</span>);
  gtk_window_set_child (window, label);

  gtk_window_present (window);
}

<span class="org-type">int</span>
<span class="org-function-name">main</span> (<span class="org-type">int</span>    <span class="org-variable-name">argc</span>,
      <span class="org-type">char</span> **<span class="org-variable-name">argv</span>)
{
  g_autoptr(GtkApplication) app = <span class="org-constant">NULL</span>;

  app = gtk_application_new (<span class="org-string">"org.sadiqpk.example"</span>, 0);
  g_signal_connect (app, <span class="org-string">"activate"</span>, G_CALLBACK (activate_cb), <span class="org-constant">NULL</span>);

  <span class="org-keyword">return</span> g_application_run (G_APPLICATION (app), argc, argv);
}
</pre>
</div>

<p>
The above code is a simple example that works with both GTK3 and GTK4.
If you need a feature rich template to develop GTK applications, see
<a href="https://www.sadiqpk.org/projects/my-gtemplate.html">My GTemplate</a> project.
</p>
</div>
</div>
</div>
</div>]]></content>
  </entry>

</feed>
