Summary

Emacs Lisp

Learning

converting list to string

(setq vetted-human-kfupm-emails
      '("hali" "mamohsin")
      )

(defvar vetted-human-kfupm-emails
      '("hali" "mamohsin")
      )

(format "%s" vetted-human-kfupm-emails) ;; to print
(message "%s" vetted-human-kfupm-emails) ;; to print
(setq query (concat "from:" (mapconcat 'identity vetted-human-kfupm-emails " OR from:")))

(setq vetted-query (concat "(maildir:/kfupm/Inbox) AND " "from:" (mapconcat 'identity vetted-human-kfupm-emails " OR from:")))
(message "%s" query)
(message "%s" vetted-query)

interactive

to make function visible be called from emac ui

(defun jak/add-to-kfupm-vetted-emails-list (username)
  (interactive "sUSERNAME: ") ;; s -> string n-> number
;; USERNAME will be displayed in buffer
  (add-to-list 'vetted-human-kfupm-emails username)
  )

append


(defcustom jak/boss-emails nil
  ""
  :type '(repeat string)
  )

(defcustom jak/people-i-know-at-kfupm  nil
  ""
  :type '(repeat string)
  )

(defcustom jak/ictc-colleagues-emails nil
  ""
  :type '(repeat string)
  )

(defcustom jak/kfupm-colleagues-emails nil
  ""
  :type '(repeat string)
  )
  (setq jak/people-i-know-at-kfupm (append jak/boss-emails jak/ictc-colleagues-emails jak/kfupm-colleagues-emails))

(message "%s" jak/people-i-know-at-kfupm)

(defun jak/set-people-i-know-at-kfupm()
  (setq jak/people-i-know-at-kfupm (append jak/boss-emails jak/ictc-colleagues-emails jak/kfupm-colleagues-emails))
(message "%s" jak/people-i-know-at-kfupm)
  )
(jak/set-people-i-know-at-kfupm)

saving variable pro grammatically to custom-file

(defun jak/add-to-boss-emails (username)
  (interactive "sBOSS_USERNAME: ")
  (add-to-list 'jak/boss-emails username)
  (customize-save-variable 'jak/boss-emails jak/boss-emails) ;; ***** setq and
;; from here:https://stackoverflow.com/a/17473323/5305401
;; tried setq and other ways of settings variables
;; they did work: user variables were not getting stored
;; https://macowners.club/posts/setq-vs-customize-set-variable/
  (jak/set-people-i-know-at-kfupm)
  (jak/set-boss-query)
  )


Custom variables

init configuration variables that can be edited and Emacs stores the customization.

defcustom

defcustom builds on defvar. It tells emacs that it is a variable, and it allows the developer to create a custom interface to set the value. The developer can say, things like “this variable can contain only the value ‘foo or ‘bar”. more ways to setting variables how to customize using easy customization interface