How to make swank working with stumpw? - emacs

I've added this code snippet to my stumpwmrc file:
(defun load-swank ()
"Load a swank server"
(ql:quickload 'swank)
(require 'swank)
(setq swank:*use-dedicated-output-stream* nil)
(setq slime-net-coding-system 'utf-8-unix)
(swank:create-server :port 4006))
(load-swank)
I am expecting to open a socket server, accepting the "swank" protocol. Thus I could connect to it with emacs (thanks to Slime).
But when I login and and stumpwm is reading its configuration file, here is the error message I get:
15:00:34 Outputting a message:
^B^1*Error loading ^b/home/ybaumes/.stumpwmrc^B: ^nThe name "SWANK" does not designate any package.
How can I fix that? I invoke 'require, or even 'quickload functions. What's the issue here?

A typical error is this:
You load the file and the reader sees the code:
SWANK is not loaded
(defun load-swank ()
"Load a swank server"
SWANK is not loaded
(ql:quickload 'swank)
SWANK is not loaded - remember, we are still reading the form.
(require 'swank)
SWANK is not loaded - remember, we are still reading the form.
Now use us a symbol in package which is not existing... the reader complains:
(setq swank:*use-dedicated-output-stream* nil) ; the package SWANK does not exist yet.
(setq slime-net-coding-system 'utf-8-unix)
(swank:create-server :port 4006))
Now you want to load SWANK:
(load-swank)
You can't use a symbol from a package which does not exist.
For example what works is this inside the function:
(setf (symbol-value (read-from-string "swank:*use-dedicated-output-stream*")) nil)
and so on.
You need to find the symbol at runtime of that function. Use (find-symbol "FOO" "SWANK") (remember Common Lisp is upcase internally) or (read-from-string "SWANK::FOO").

Related

ox-hugo github actions : Debugger entered--Lisp error: (void-function org-hugo-export-wim-to-md) Error: Process completed with exit code 255

Im trying to deploy my hugo site on github actions. Im using the following github action which does the following :
1.On Ubuntu
2.Setup up emacs
3.git clone ox-hugo package
4.ox-hugo package should convert my .org files to .md
setup and build using Hugo and deploy
https://gist.github.com/shwetarkadam/d890b7054b65fe21b63609ca03650bdc
I'm facing an issue on step 4 where I encounter the following error on GitHub action :
Run emacs ./config.org --batch -L ./ox-hugo -L ox-hugo.el --eval="(org-hugo-export-wim-to-md t)" --kill
Debugger entered--Lisp error: (void-function org-hugo-export-wim-to-md)
(org-hugo-export-wim-to-md t)
eval((org-hugo-export-wim-to-md t) t)
command-line-1(("./config.org" "-L" "./ox-hugo" "-L" "ox-hugo.el" "--eval=(org-hugo-export-wim-to-md t)" "--kill"))
command-line()
normal-top-level()
Approaches tried till now :
Changing (org-hugo-export-wim-to-md t) to (org-hugo-export-wim-to-md :all-subtrees)
Adding the expression (org-hugo-export-wim-to-md :all-subtrees) in single quotes and double quotes.
I happened to be working on a similar problem today. I had searched for guidance on it and I stumbled across Batch export of org-mode files from the command line which led me to fniessen/orgmk and in orgmk.el in particular.
After experimenting in my *scratch* buffer and asking Emacs' various help facilities a few questions, I bludgeoned my way to a standalone file containing Emacs Lisp code that appears to work independently of my initialization files.
$ touch export.el
$ emacs -q --batch -l export.el
Designating package sites
Designating package site melpa-stable => https://stable.melpa.org/packages/
Designating package site melpa => https://melpa.org/packages/
Designating package site gnu => https://elpa.gnu.org/packages/
Installing package ox-hugo
Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations
‘ox-hugo’ is already installed
Exporting org subtrees to hugo from content.org
1 files scanned, 0 files contains IDs, and 0 IDs found.
[ox-hugo] 1/ Exporting ‘Redacted site title’ ..
[ox-hugo] 2/ Exporting ‘Posts’ ..
[ox-hugo] 3/ Exporting ‘Redacted post title’ ..
[ox-hugo] Exported 3 subtrees from content.org in 0.510s (0.170s avg)
Exporting all org subtrees in all files in /redacted/directory
$ find content -newer export.el
content
content/_index.md
content/posts
content/posts/redacted-post-title.md
content/posts/_index.md
(Some names have been changed to protect the guilty er um I mean innocent.)
The file export.el contains:
(defvar my/package-archives
(list
(cons "melpa-stable" "https://stable.melpa.org/packages/")
(cons "melpa" "https://melpa.org/packages/")
(cons "gnu" "https://elpa.gnu.org/packages/")))
(defvar my/packages-to-install '(ox-hugo))
(defun my/designate-package-site (site)
(message "Designating package site %s => %s" (car site) (cdr site))
(add-to-list 'package-archives site t))
(defun my/designate-package-sites ()
(message "Designating package sites")
(mapcar #'my/designate-package-site my/package-archives))
(defun my/install-package (pkg)
(message "Installing package %s" pkg)
(ignore-errors (package-install pkg)))
(when (locate-library "package")
(require 'package)
(my/designate-package-sites)
(package-initialize)
(unless package-archive-contents (package-refresh-contents))
(mapcar #'my/install-package my/packages-to-install))
(defun my/batch-ox-hugo-file (file)
(message "Exporting org subtrees to hugo from %s" file)
(let ((all-subtrees t)
(any-visibility nil))
(with-current-buffer (find-file-noselect file)
(org-hugo-export-wim-to-md all-subtrees any-visibility))))
(defun my/batch-ox-hugo-directory (directory)
(message "Exporting all org subtrees in all files in %s" directory
(let ((default-directory (expand-file-name directory)))
(mapcar #'my/batch-ox-hugo-file
(file-expand-wildcards "*.org")))))
(my/batch-ox-hugo-directory default-directory)
The execution environment where I developed this is Emacs 28.2 on FreeBSD 13.1.
I haven't tried it out with Github Actions yet, but that's my next step.

Org-journal won't recognize org-journal-dir?

Using the following use-package syntax, Org-journal doesn't recognize the org-journal-dir setting--instead, attempts to create a different directory with query Journal directory ~/Documents/journal not found. Create one?:
(use-package org-journal
:ensure t
:custom
(setq org-journal-dir "~/Dropbox/logs/journal/")
(setq org-journal-file-format "%m.%d.%Y.org"))
I see no error messages--it just seems to ignore the directory setting. Is this a simple syntax error? I'm new to the package and to Org mode.
[Update]: Sometimes, I get the following error message on Emacs start:
Error (use-package): org-journal/:catch: Symbol’s value as variable is void: org-journal-dir
The syntax for :custom is wrong. See https://github.com/jwiegley/use-package#customizing-variables. It should be something like:
:custom
(org-journal-dir "~/Dropbox/logs/journal/")
(org-journal-file-format "%m.%d.%Y.org")
Either that, or use :config (or maybe :init, but probably not) with setq:
:config
(setq org-journal-dir "~/Dropbox/logs/journal/")
(setq org-journal-file-format "%m.%d.%Y.org")

How should I configure Vulkan for cider-jack-in?

I'm working through the newly released Vulkan Tutorial in Clojure with CIDER, and I've hit a bit of a snag. The example makefile project works perfectly, but I'm having trouble translating it into Clojure.
My build.boot file just specifies the :source-paths and adds LWJGL as a dependency:
(set-env!
:source-paths #{"src"}
:dependencies
(let [lwjgl-version "3.0.0"]
[['org.lwjgl/lwjgl lwjgl-version]
['org.lwjgl/lwjgl-platform lwjgl-version :classifier "natives-linux"]]))
Then, in src/example/core.clj, I have an extension-count function that uses vkEnumerateInstanceExtensionProperties as demonstrated in the original example:
(ns example.core
(:import (org.lwjgl.vulkan VK10)))
(defn extension-count []
(let [^String layer-name nil
property-count (int-array 1)]
(VK10/vkEnumerateInstanceExtensionProperties layer-name property-count nil)
(first property-count)))
Now, from Bash, I can set the relevant environment variables LD_LIBRARY_PATH and VK_LAYER_PATH as I start up a REPL:
$ VULKAN_SDK_PATH=~/VulkanSDK/1.0.21.1/x86_64 LD_LIBRARY_PATH=$VULKAN_SDK_PATH/lib VK_LAYER_PATH=$VULKAN_SDK_PATH/etc/explicit_layer.d boot repl
boot.user=> (require '[example.core :refer [extension-count]])
nil
boot.user=> (extension-count)
4
As you can see, everything works correctly. But of course, when I use cider-jack-in by C-c M-j instead, I get an UnsatisfiedLinkError because CIDER isn't setting those variables:
boot.user> (import (java.util.function Consumer)
(org.lwjgl.system Configuration))
org.lwjgl.system.Configuration
boot.user> (Configuration/setDebugStreamConsumer
(reify Consumer
(accept [_ message]
(println message))))
nil
boot.user> (require '[example.core :refer [extension-count]])
nil
boot.user> (extension-count)
[LWJGL] Failed to load a library. Possible solutions:
a) Set -Djava.library.path or -Dorg.lwjgl.librarypath to the directory that contains the shared libraries.
b) Add the JAR(s) containing the shared libraries to the classpath.
[LWJGL] Enable debug mode with -Dorg.lwjgl.util.Debug=true for better diagnostics.
java.lang.UnsatisfiedLinkError: Failed to locate library: libvulkan.so.1
Am I supposed to be setting java.library.path or org.lwjgl.librarypath, as suggested in the above error message, instead of LD_LIBRARY_PATH? I can set either of those variables from profile.boot:
(System/setProperty
"java.library.path"
(str (System/getProperty "user.home") "/VulkanSDK/1.0.21.1/x86_64/lib"))
Now when I try C-c M-j again, it works:
boot.user> (require '[example.core :refer [extension-count]])
nil
boot.user> (extension-count)
4
However, this still doesn't let me set VK_LAYER_PATH, which will be fairly important in the future:
We will start using validation layers in Vulkan and you need to tell the Vulkan library where to load these from using the VK_LAYER_PATH variable:
test: VulkanTest
LD_LIBRARY_PATH=$(VULKAN_SDK_PATH)/lib VK_LAYER_PATH=$(VULKAN_SDK_PATH)/etc/explicit_layer.d ./VulkanTest
How can I set these environment variables for cider-jack-in? I'd prefer not to have to manually configure CIDER's dependencies for a standalone repl in a separate terminal and then connect to it using cider-connect, but if there's no other option here, I guess that's what I'll have to do.

How to use usocket to create a connection? (common lisp)

I'm trying to use socket in lisp to create a connection. Using sbcl, i found "usocket" available. But I failed to sending strings between the server and client. Here's the code:
Server:
(ql:quickload "usocket")
(use-package 'usocket)
(defun default-tcp-handler (stream) ; null
(declare (type stream stream))
(terpri stream))
(defparameter *us* (socket-server "127.0.0.1" 4547 #'default-tcp-handler))
(defparameter *s* (socket-accept *us*))
(defparameter *ss* (usocket:socket-stream *s*))
Client:
(ql:quickload "usocket")
(use-package 'usocket)
(defparameter *us* (socket-connect "127.0.0.1" 4547))
(defparameter *st* (usocket:socket-stream *us*))
I ran the server code first, it freezes. Then I ran the client code. But the server seemed to be no response.
I tried to format a string into the st stream:
(format *st* "hello, server")
But it returns nil.
How can i solve the problem??
Thanks a lot.
I tried your code and there were no errors, so everything seemed to be all right with the connection. However, if you only write to streams without reading (not to mention flushing the output), the connection has no way to manifest itself. Here is a modified version where the server reads a single line from the socket:
;;; server
(ql:quickload "usocket")
(use-package :usocket)
(defun default-tcp-handler (stream)
(declare (type stream stream))
(format t "~A~%" (read-line stream))
(finish-output))
(defparameter *us* (socket-server "127.0.0.1" 4547 #'default-tcp-handler))
;;; client
(ql:quickload "usocket")
(use-package :usocket)
(defparameter *us* (socket-connect "127.0.0.1" 4547))
(defparameter *st* (socket-stream *us*))
(write-line "hello server" *st*)
(finish-output *st*)
In your case format returned nil, because it always returns nil except format nil. The server hangs because it starts listening. If you don't want that, you'll have to work with multiple threads.

Proper way of defining packages using asdf:defsystem and quickproject

I'm a Lisp beginner trying to understand how to properly use Lisp package system while learning LTK for GUI programming, using SBCL 1.0.55.0.debian and Limp 0.3.4 (and Debian Wheezy if that matters). I have installed ASDF using aptitude package manager (packages cl-asdf & cl-common-lisp-controller), then I installed Quicklisp using the instructions on Quicklisp website (http://www.quicklisp.org/beta/index.html) (not from Debian repository) and then I have installed LTK with (ql:quickload 'ltk) in SBCL console.
hello-1.lisp (directly from LTK tutorial):
(defun hello-1()
(with-ltk ()
(let ((b (make-instance ’button
:master nil
:text "Press Me"
:command (lambda ()
(format t "Hello World!~&")))))
(pack b))))
If I compile this straight on in a new SBCL Lisp image, I get the message that WITH-LTK and PACK are undefined functions and 'BUTTON is undefined variable.
So, I found out that I need to load 'ltk first and then use in-package.I to be able to run it, I first have to use (ql:quickload 'ltk) and (in-package :ltk) in SBCL console. However, I still an error message that 'BUTTON is undefined variable.
* (ql:quickload 'ltk)
To load "ltk":
Load 1 ASDF system:
ltk
; Loading "ltk"
(LTK)
* (in-package :ltk)
#<PACKAGE "LTK">
* (compile-file "/home/user/code/lisp/hello-1.lisp")
; caught WARNING:
; undefined variable: ’BUTTON
;
; compilation unit finished
; Undefined variable:
; ’BUTTON
; caught 1 WARNING condition
; /home/user/code/lisp/hello-1.fasl written
; compilation finished in 0:00:00.009
#P"/home/user/code/lisp/hello-1.fasl"
T
T
*
Then, as this didn't work out as I wanted, I also attempted to define my own package definitions according to the answers of another question (Problems with ltk (common lisp)), Xach's blog entry "Making a small Lisp project with quickproject and Quicklisp" http://xach.livejournal.com/278047.html?thread=674335 and ASDF Manual (http://common-lisp.net/project/asdf/asdf/The-defsystem-form.html) using quickproject:make-project, but without success. Currently I have the following files:
package.lisp (compiles cleanly if I first (ql:quickload 'ltk) SBCL REPL):
(defpackage :hello-world-ltk-system
(:use :cl :asdf :ltk))
hello-world-ltk.asd (compiles cleanly after I have first compiled package.lisp):
(in-package :hello-world-ltk-system)
(asdf:defsystem :hello-world-ltk
:serial t
:description "Describe hello-world-ltk here"
:author "Your Name <your.name#example.com>"
:license "Specify license here"
:depends-on (:cl :asdf :ltk)
:components ((:file "package")
(:file "hello-world-ltk")))
hello-world-ltk.lisp (I get compile error The name "HELLO-WORLD-LTK" does not designate any package).
(require 'hello-world-ltk)
(in-package :hello-world-ltk)
(defun hello-world-1 ()
(with-ltk ()
(let ((b (make-instance 'button
:master nil
:text "Press me!"
:command (lambda ()
(format t "Hello world!~&")))))
(pack b))))
When I attempt to compile this hello-world-ltk.lisp after successfully compiling package.lisp and hello-world-ltk.asd (which all reside in the same directory) I get the following error:
; compiling (IN-PACKAGE :HELLO-WORLD-LTK)
debugger invoked on a SB-KERNEL:SIMPLE-PACKAGE-ERROR in thread
#<THREAD "initial thread" RUNNING {10029A0FA3}>:
The name "HELLO-WORLD-LTK" does not designate any package.
Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.
(SB-INT:%FIND-PACKAGE-OR-LOSE "HELLO-WORLD-LTK")
0]
(load "/home/user/code/lisp/hello-world-ltk/hello-world-ltk")
debugger invoked on a SIMPLE-ERROR in thread
#<THREAD "initial thread" RUNNING {10029A0FA3}>:
attempt to load an empty FASL file:
"/home/user/code/lisp/hello-world-ltk/hello-world-ltk.fasl"
Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Reduce debugger level (to debug level 1).
1: Exit debugger, returning to top level.
(SB-FASL::LOAD-AS-FASL
#<SB-SYS:FD-STREAM
for "file /home/user/code/lisp/hello-world-ltk/hello-world-ltk.fasl"
{1005291233}>
NIL
#<unavailable argument>)
0[2]
So, I'm quite lost here with all different ways to define packages, ASDF, Quicklisp, package.lisp, quickproject, asdf:defsystem, require and ql:quickload... quickproject:make-project looks promising, but I really don't know what's still wrong with my source files. I'm looking for a solution that should handle all the compilations and package loadings preferibly in one single command for the whole project and that should be extendable for bigger projects too.
Thank you for any help :)
The first problem in your code is that you use apostrophe (’) instead of tick ('). That's why you get undefined variable error, as ’button is read as variable name (it's not quoted).
Now regarding packages and systems. A package is defined with defpackage and it is a collection of symbols, which are used after the in-package form inside a file (or in interactive session). A package has internal and external (exported) symbols, that can be accessed as package::internal-symbol and package:external-symbol respectively. Packages can also import symbols from other packages. If you use-package, you import all its external symbols. While in-package switches the current package to the specified one and you start to define symbols in it (and it is not desirable to do such things in 3rd-party packages, like LTK). So if you want to use LTK symbols, like with-ltk or button, you just need to either use-package LTK or import these symbols from LTK in your defpackage form:
(defpackage :hello-world-ltk-system
(:use :cl)
(:import-from :ltk :with-ltk :button))
or simply import all LTK symbols (with use clause):
(defpackage :hello-world-ltk-system
(:use :cl :ltk))
Finally, systems and packages are totally unrelated things. A system is an instance of a class ASDF:SYSTEM, which holds information about physical files and their relations, so that they can be compiled and loaded appropriately. For your hello-world application I would suggest, that you don't bother about systems for now, and write all your code in one file. This file should start with a defpackage form, followed by in-package, and then the rest of your code.
When this file will grow large enough, that you'll see clear parts in it, you can factor out those parts into separate files. Then you'll have to create a system definition file, that will look like this:
(asdf:defsystem :hello-world
:depends-on (:ltk)
:serial t
:components ((:file "package")
(:file "first")
(:file "second")
...))
The "package.lisp" file will now hold your package definition.