Start a new topic

Let's share init.org customizations

I suggest we use this topic to share the scheme code that we write in init.org to add cool stuff.

This will allow others to use it, give some new ideas, and maybe some gurus will suggest better ways to do things.


Here is what I have now:


- Inserting src_calc entry and a simple table. No rocket science here, but someday I hope I will be able to write something to parse and get the calculations done, at least for src_calc.

  (define (insert-src-calc)
    (insert "src_calc{}")
    (backward-char))
  (define (insert-usual-table)
    (insert "|---------+---+---|\n| x | | |\n| x | | |\n|---------+---+---|\n| *Total* | | 0 |\n|---------+---+---|\n#+TBLFM: @>$3=vsum(@1$2..@-1$2)-vsum(@1$3..@-1$3)")
    (goto-char (- (point) 146)))

  

- Transform commands: I added bold / italic / underline. I had no luck with capitalize / titlecase, maybe not implemented in BiwaScheme.

  (define (show-transform-commands)
    (if (string=? (region) "")
        (alert "" "No text is selected.")
        (sheet '(("Uppercase" (region-text-set (string-upcase (region))))
                 ("Lowercase" (region-text-set (string-downcase (region))))
                 ("Capitalize" (region-text-set (string-titlecase (region))))
                 ("Boldface" (region-text-set (string-append "*" (region) "*")))
                 ("Italic" (region-text-set (string-append "/" (region) "/")))
                 ("Underline" (region-text-set (string-append "_" (region) "_")))))))

 

- Increment / decrement number: I wanted that to change a date easily from today to tomorrow, etc. First I made a separate function bundled to a separate button, then I realized that ">" and "<" can be used to move cursor if nothing is selected, or increment/decrement if a number is selected. I think I will soon do some pattern matching on (region), to be able to do other stuff (cycle between TODO status, change "Thu" to "Fri", whatever).

  (define (increment-number)
    (if (string=? (region) "")
        (alert "" "No text is selected.")
        (region-text-set (number->string (+ (string->number (region)) 1)))))
  (define (decrement-number)
    (if (string=? (region) "")
        (alert "" "No text is selected.")
        (region-text-set (number->string (- (string->number (region)) 1)))))
  (define (forward-char-or-increment-number)
    (if (string=? (region) "")
        (forward-char)
        (region-text-set (number->string (+ (string->number (region)) 1)))))
  (define (backward-char-or-decrement-number)
    (if (string=? (region) "")
        (backward-char)
        (region-text-set (number->string (- (string->number (region)) 1)))))

 

- Insert a date, today or any day. Ok, you will tell me that the outline edit box has something like this, but only to add schedule or deadline dates at the top of comments. I want to insert any date, inactive, at any point in the text.

I started with today, and then I am quite stuck, as I don't know how to display a date choice dialog box, and as it seems that date functions such as add-duration or current-seconds, or most functions from SRFI section 19, are not implemented in BiwaScheme.

  (define (insert-some-date)
        (sheet '(("Today" (insert (date->string (current-date) "[~Y-~m-~d ~a]")))
                 ("Tomorrow" (insert (date->string (seconds->date (+ (current-seconds) 86400)) "[~Y-~m-~d ~a]"))))))

 


I do intend on (slowly!) improving BiwaScheme (and of course submitting pull requests to the project) to add missing functionality. I have a fork ready but haven't yet made any improvements (https://github.com/mgkennard/biwascheme).


You might find it useful to see the JavaScript file I've built from the source which is then included in beorg. I've attached to this post. You can search in this for functions to see if they have been implemented - for example string-titlecase hasn't (there are placeholders for most functions which are yet to be added).


There are also some additional functions defined in JavaScript which bridge to native code - I have attached the JavaScript for this also.


Documentation is lacking for both BiwaScheme and what beorg offers in terms of Scheme. Both of these I hope to address.


Also over time I hope to expose things such as the date dialog (I've added this to my possible future improvements list) via Scheme. Hopefully if I can see how people are using Scheme on the forum that will provide lots of ideas for improvement.

js
js

1 person likes this

Clock in and clock out

  

#+BEGIN_SRC scheme

(define (clock-in)
  (insert ":LOGBOOK:\nCLOCK: \n:END:\n")
  (goto-char (- (point) (string-length "\n:END:\n")))
  (insert (date->string (current-date) "[~Y-~m-~d ~a ~H:~M]"))
  (goto-char (+ (point) (string-length "\n:END:\n")))
  )

(define (clock-out)
  (insert (date->string (current-date) "--[~Y-~m-~d ~a ~H:~M]"))
  (goto-char (point-max)))

(set! editor-toolbar-items '(("icon-time" (clock-in))
                             ("icon-clock" (clock-out))
                             ("icon-left" (backward-char))
                             ("icon-right" (forward-char))
                             ("icon-list" (insert "+ "))
                             ("icon-change" (show-transform-commands))
                             ("icon-settings" (insert-code-snippet))))
#+END_SRC
 

   


1 person likes this

Back to the "inserting some date" function.

 Thanks to the date picker availability, that's just too easy now 

  (define (insert-some-date-with-date-picker)
          (date-picker (current-date)
	               #f
		       (lambda (removed date includes-time)
		               (if (not removed)
			           (insert (date->string date "[~Y-~m-~d ~a]"))))))

 

Increment / decrement number: (...) then I realized that ">" and "<" can be used to move cursor if nothing is selected, or increment/decrement if a number is selected. I think I will soon do some pattern matching on (region), to be able to do other stuff (cycle between TODO status, change "Thu" to "Fri", whatever).


About this one, I think rxmatch would be nice, but it doesn't look implemented in BiwaScheme now (actually, there is some code but it is commented). So that will wait :)

Date insertion, final version:

 

  (define (insert-some-date-with-date-picker-from-selection)
    (let ((starting-date (if (string=? (region) "")
                         (current-date)
			 (parse-date (region)))))
         (date-picker starting-date
	               #f
		       (lambda (cancelled date includes-time)
		               (if (not cancelled)
			           (if (not includes-time)
			               (insert (date->string date "[~Y-~m-~d ~a]"))
			               (insert (date->string date "[~Y-~m-~d ~a ~H:~M]"))))))))

 

Login or Signup to post a comment