;; 10-pkgs.el --- Various XE Package Settings

;; Copyright (C) 2007 - 2020 Steve Youngs

;;     Author: Steve Youngs <steve@sxemacs.org>
;; Maintainer: Steve Youngs <steve@sxemacs.org>
;;    Created: <2007-12-02>
;; Time-stamp: <Saturday Apr 18, 2020 21:13:16 steve>
;;   Download: <https://downloads.sxemacs.org/SYinits>
;;   HTMLised: <https://www.sxemacs.org/SYinits/10-pkgs.html>
;;   Git Repo: git clone https://git.sxemacs.org/syinit
;;   Keywords: init, compile

;; This file is part of SYinit

;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
;; are met:
;;
;; 1. Redistributions of source code must retain the above copyright
;;    notice, this list of conditions and the following disclaimer.
;;
;; 2. Redistributions in binary form must reproduce the above copyright
;;    notice, this list of conditions and the following disclaimer in the
;;    documentation and/or other materials provided with the distribution.
;;
;; 3. Neither the name of the author nor the names of any contributors
;;    may be used to endorse or promote products derived from this
;;    software without specific prior written permission.
;;
;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;; DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

;;; Commentary:
;;
;;   Lots of settings for various XEmacs packages that I use.  Plus a
;;   few other packages.
;;
;;   I want to point out that I DO NOT blindly install the "sumo"
;;   packages.  I only install what I need and use.  And I absolutely
;;   DO NOT have the "fsf-compat" package installed, although I do
;;   have overlay.el from there.  It just makes my life a tad easier.

;;; Credits:
;;
;;   The HTML version of this file was created with Hrvoje Niksic's
;;   htmlize.el which is part of the XEmacs "text-modes" package.
;;

;;; Todo:
;;
;;

;;; Code:
;:*======================
;:* MusicPD  (Not an XEmacs package)
(require 'mpd)

(defun sy-mpd-play ()
  "Start playing music from a randomly chosen playlist."
  (interactive)
  (mpd-send "clear")
  (mpd-send "load Full-sorted.playlist")
  (mpd-send "random 1")
  (mpd-send "repeat 1")
  (mpd-playpause))

(defun 2001-mpd-play ()
  "Start playing 2001 audio book."
  (interactive)
  (mpd-send "clear")
  (mpd-send "load 2001_A_Space_Odyssey.playlist")
  (mpd-send "random 0")
  (mpd-send "repeat 0")
  (mpd-playpause))

;; Audio keybindings
(global-set-key [XF86AudioPlay] #'mpd-playpause)
(global-set-key [XF86AudioStop] #'mpd-stop)
(global-set-key [XF86AudioNext] #'mpd-next-track)
(global-set-key [XF86AudioPrev] #'mpd-previous-track)
(global-set-key [XF86AudioRaiseVolume] #'mpd-volume-up)
(global-set-key [XF86AudioLowerVolume] #'mpd-volume-down)
(global-set-key [XF86AudioMute] #'mpd-volume-mute/unmute)

;; Mpd frame props
(unless (or (string= (getenv "KDE_FULL_SESSION") "true")
            (string= (getenv "SAWFISH_IS_RUNNING") "true"))
  (push (cons 'override-redirect t) mpd-dock-frame-plist))
(push (cons 'left 1780) mpd-dock-frame-plist)
(push (cons 'top 5) mpd-dock-frame-plist)
(push (cons 'internal-border-width 4) mpd-dock-frame-plist)
(push (cons 'border-width 1) mpd-dock-frame-plist)
(push (cons 'border-color "red") mpd-dock-frame-plist)

;:*======================
;:* View-process (`top' for emacs)
(require 'view-process-mode)
(setq View-process-host-names-and-system-types
      '(("bastard.steveyoungs.com"
         ("linux" nil "bsd"
          View-process-field-name-descriptions-linux
          View-process-kill-signals-linux))))
(setq View-process-status-command-switches-system-v "auxw")
(setq View-process-ps-header-window-offset 3)
(add-hook 'View-process-header-mode-hook
          (lambda ()
            (set-specifier horizontal-scrollbar-visible-p nil (current-buffer))
            (set-specifier vertical-scrollbar-visible-p nil (current-buffer))))

;:*=====================
;:* whitespace-mode
(autoload 'whitespace-mode "whitespace-mode" nil t)
(autoload 'whitespace-incremental-mode "whitespace-mode" nil t)

;:*======================
;:* func-menu
(require 'func-menu)
(add-hook 'find-file-hooks 'fume-setup-buffer)
(add-hook 'Manual-mode-hook 'turn-on-fume-mode)
(define-key fume-mode-map [(control button3)] #'mouse-function-menu)
(setq
 fume-display-in-modeline-p t
 fume-menu-path '("View"))

;:*======================
;:* recent-files.el --- Maintain menu of recently opened files.
(when (featurep 'menubar)
  (require 'recent-files)
  (setq recent-files-non-permanent-submenu t
        recent-files-menu-path '("File")
        recent-files-add-menu-before "Insert File..."
        recent-files-save-file
        (expand-file-name ".recent-files.el" user-init-directory)
        recent-files-dont-include
        '(#r"\.config/sxemacs/\(howm\|diary\).*$"
          #r"sxemacs/timelog$"
          #r"info/dir$"
          #r"\.\(newsrc*\|bbdb\)$"
          #r"init\.d\.el"))
  (recent-files-initialize))

;:*======================
;:* jka-compr
;; Handle automatic (de)compresion of [bg]zip files
(require 'jka-compr)
(jka-compr-install)

;:*======================
;:* iswitchb
;: A really cool package to switch buffers
(require 'iswitchb)
(setq iswitchb-default-method 'samewindow)
(iswitchb-default-keybindings)
(add-hook
 'iswitchb-define-mode-map-hook
 '(lambda ()
    (define-key iswitchb-mode-map " " 'iswitchb-next-match)
    (define-key iswitchb-mode-map [(control ?\ )] 'iswitchb-prev-match)
    (define-key iswitchb-mode-map "\C-a" 'iswitchb-toggle-ignore)))

;:*======================
;:* backup
;:  move all backups in one directory
(require 'backup-dir)
(setq bkup-backup-directory-info
      '((t "~/.autosave/" ok-create full-path)))
(setq version-control 'preserve-prefer-numbered)
(setq-default delete-old-versions t)

;:*======================
;:* Load minibuffer history, but only if mule or file-coding is available
(when (featurep '(or mule file-coding))
  (require 'savehist)
  (setq savehist-file (expand-file-name "history" user-init-directory))
  (setq savehist-coding-system
        (coding-system-name (find-coding-system 'utf-8)))
  (savehist-mode 1))

;:*======================
;:* Kyle Jones' redo package.
(when running-xemacs
  (require 'redo)
  (global-set-key [(control f2)] 'redo))

(require 'scroll-in-place)

;:*======================
;:* pending-del
;:  Non-nil when Pending Delete mode is enabled. In Pending Delete mode, typed
;:  text replaces the selected region. Normally, you shouldn't modify this
;:  variable by hand, but use the function `pending-delete-mode' instead. However,
;:  you can customize the default value from the options menu (auto delete
;:  selection).
(require 'pending-del)
(turn-on-pending-delete nil)

;:*======================
;:* comment-region
;:  Comment or uncomment each line in the region.
;:  Comments are terminated on each line, even for syntax in which newline does
;:  not end the comment.  Blank lines do not get comments.
(require 'newcomment)
(global-set-key '(control f12)  'comment-or-uncomment-region)
(global-set-key '(meta f12) 'comment-or-uncomment-region)

;;; FIXME: SXEInits
;:*======================
;:* parens that mark sexpressions
(require 'paren)
(paren-set-mode 'paren)

;:*======================
;:* easy editing of crontab files
(require 'crontab-edit "crontab.elc")
(setq crontab-delete-blank-lines nil)
(setq crontab-filename (expand-file-name ".crontab" (user-home-directory)))
(setq crontab-directory
      (paths-construct-path '("spool" "cron" "crontabs") "/var"))

;:*======================
;:* a major mode for editing X resource database files
(autoload 'xrdb-mode "xrdb-mode" "Mode for editing X resource files" t)

;:*======================
;:* Footnote package
(require 'footnote)

;:*======================
;:* Filladapt-Mode
(require 'filladapt)
(setq-default filladapt-mode t)
(setq filladapt-fill-column-tolerance 5)
(add-hook 'c-mode-hook 'turn-off-filladapt-mode)

;:*======================
;:* Speedbar
;;; FIXME:  Speedbar Tooltips
;;; snap:///${XPKGS}/speedbar/speedbar.el
(setq
 speedbar-query-confirmation-method 'none-but-delete
 speedbar-show-unknown-files t
 speedbar-tag-hierarchy-method '(speedbar-prefix-group-tag-hierarchy
                                 speedbar-trim-words-tag-hierarchy
                                 speedbar-simple-group-tag-hierarchy
                                 speedbar-sort-tag-hierarchy)
 ;; speedbar-track-mouse-flag t
 ;; speedbar-use-tool-tips-flag t
 speedbar-visiting-tag-hook 'speedbar-recenter-to-top)

(when (featurep 'menubar)
  (add-menu-button '("Tools")
                   ["Speedbar" speedbar-frame-mode
                    :style toggle
                    :selected (and (boundp 'speedbar-frame)
                                   (frame-live-p speedbar-frame)
                                   (frame-visible-p speedbar-frame))]
                   "--"))
(global-set-key [(f4)] 'speedbar-get-focus)
(require 'sb-image)
(require 'sb-info)
(require 'sb-texinfo)
(eval-after-load "speedbar" '(load-library "sb-texinfo"))
(eval-after-load "speedbar" '(load-library "sb-html"))
(autoload 'w3-speedbar-buttons "sb-w3"
  "W3 specific speedbar button generator.")

;;; Speedbar frame props
;;  'name' (so I can use matched windows in Sawfish)
(setq speedbar-frame-plist
      (plist-put speedbar-frame-plist 'name "Speedbar::Frame"))
;; No scrollbars
(setq speedbar-frame-plist
      (plist-put speedbar-frame-plist 'scrollbar-height 0))
(setq speedbar-frame-plist
      (plist-put speedbar-frame-plist 'scrollbar-width 0))
;; A little wider than default
(setq speedbar-frame-plist
      (plist-put speedbar-frame-plist 'width 25))

;; FIXME: see... PKGFix
;; Try to load the speedbar on the right of the current frame
(defalias 'dframe-reposition-frame-xemacs 'dframe-reposition-frame-emacs)
(setq speedbar-default-position 'right)

;; Speedbar only does the repositioning thing if the frame has to be
;; created.  If you have only closed the speedbar frame with 'q'
;; instead of deleting it with 'Q' then the frame remains live.  As
;; there is no perceptible speed difference of coming back from
;; either a closed or deleted speedbar frame the following will
;; force a delete-frame even if you are only closing it.
(defun sy-speedbar-kill ()
  (when (frame-live-p speedbar-frame)
    (delete-frame speedbar-frame)))

(add-hook 'speedbar-before-delete-hook #'sy-speedbar-kill)


;:*======================
;:* Shell-mode
;; Trying to get compilation buffers to recognise ANSI colour
;; sequences because GCC.  Doesn't seem to work.  Probably have to
;; stick to `GCC_COLORS= make'
(defun sy/comint-hooks ()
  (ansi-color-for-comint-mode-on)
  (fast-lock-mode 1)
  (font-lock-mode 1))
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'comint-mode-hook #'sy/comint-hooks)
(add-hook 'compilation-mode-hook #'sy/comint-hooks)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(add-hook 'shell-mode-hook 'turn-on-font-lock)

;:*=======================
;:* Shell-script
(setq sh-basic-offset 4)

;:*======================
;:* Compile-Mode
(setq
 compilation-always-signal-completion t
 mode-compile-make-program "GCC_COLORS= make"
 compilation-read-command t
 compilation-window-height 10
 compile-command "GCC_COLORS= make")

;:*======================
;:* Version Control
(vc-load-vc-hooks)
;; #'vc-load-vc-hooks brings in vc-xemacs which adds this hook. I
;; would never need it.
(remove-hook 'find-file-hooks 'vc-xemacs-hg-find-file-hook)
(setq
 ;; I pretty much only use git now so there's no point in VC trying to
 ;; handle any other type.
 vc-handled-backends '(GIT)
 vc-follow-symlinks t)

;:*======================
;:* Ediff & Diff-mode
(require 'ediff)
(require 'diff-mode)
(setq ediff-use-toolbar-p t
      ediff-custom-diff-options "-u"
      ediff-window-setup-function 'ediff-setup-windows-plain)
(setq diff-switches "-u")

;:*=====================
;:* Tramp
(require 'tramp)
(setq tramp-default-method "ssh"
      tramp-auto-save-directory "~/.autosave/"
      tramp-remote-path
      '("/usr/lib/pkgusr"
        "/usr/bin"
        "/bin"
        "/usr/X11R6/bin"))

; :*======================
; :* Eshell
(setq
 eshell-directory-name
 (file-name-as-directory
  (expand-file-name "eshell" user-init-directory))
 eshell-ask-to-save-history 'always
 eshell-save-history-on-exit t
 eshell-banner-message (concat "Welcome to Eshell on "
                               (system-name)
                               ", running "
                               (shell-command-to-string "uname -rs")
                               "In: "
                               emacs-version
                               "\n\n")
 eshell-hist-ignoredups t
 eshell-modules-list '(eshell-alias
                       eshell-banner
                       eshell-basic
                       eshell-cmpl
                       eshell-dirs
                       eshell-glob
                       eshell-hist
                       eshell-ls
                       eshell-pred
                       eshell-prompt
                       ;eshell-rebind
                       eshell-script
                       ;eshell-smart
                       eshell-term
                       eshell-unix
                       eshell-xtra))

(defun sy-eshell-bol-maybe (&optional prompt)
  "*Move point to beginning of command or bol if there already.
 If at bol, move point to beginning of command.
 Optional arg, PROMPT is a regexp of your eshell prompt."
  (interactive)
  (let* ((prompt (or prompt "^.+ [$%] "))
         (lbpos (point-at-bol))
         (prspos (save-excursion
                   (goto-char lbpos)
                   (search-forward-regexp prompt (point-at-eol) t)))
         (cpos (point)))
    (goto-char
     (cond ((null prspos)
            lbpos)
           ((= cpos (or prspos 0))
            lbpos)
           (prspos)
           (t lbpos)))))

(eval-when-compile (defvar eshell-mode-map))
(defun sy-eshell-bol-maybe-key ()
  (define-key eshell-mode-map [(control ?a)] 'sy-eshell-bol-maybe))

(add-hook 'eshell-mode-hook #'sy-eshell-bol-maybe)
(add-hook 'eshell-mode-hook #'sy-eshell-bol-maybe-key t)
(add-hook 'eshell-output-filter-functions #'eshell-handle-ansi-color)

(defun sy-esh-cdl (&optional type)
  "Eshell function to find current kernel's build or source dir.

 Non-nil TYPE means find the current kernel's build directory, otherwise
 find the source directory."
  (let* ((base "/lib/modules/")
         (ver (substring (shell-command-to-string "uname -r") 0 -1))
         (dir (file-name-as-directory
               (concat base ver "/"
                       (if type
                           "build"
                         "source")))))
    (cd dir)))

(defun cdls ()
  "Change directory to current kernel source directory.

 Convenience function to use with Eshell."
  (interactive)
  (sy-esh-cdl))

(defun cdlb ()
  "Change directory to current kernel build directory.

 Convenience function to use with Eshell."
  (interactive)
  (sy-esh-cdl 'build))

; :*======================
; :* FFAP -- Find File At Point
(require 'ffap)

;; Make sure ffap does NOT get in my way...
(setq ffap-bindings nil)

(global-set-key [f3] #'find-file-at-point)
(global-set-key [(control x) ?4 f3] #'ffap-other-window)
(global-set-key [(control x) ?5 f3] #'ffap-other-frame)
(global-set-key [(shift button3)] #'ffap-at-mouse)
(global-set-key [(control shift button3)] #'ffap-menu)

(setq
 ffap-machine-p-known 'accept
 ffap-machine-p-unknown 'accept
 ffap-machine-p-local 'accept)


;:*======================
;:* Auto-Insert
(require 'auto-insert-tkld)

(setq auto-insert-alist '(("\\.texi\\(nfo\\)?$" . "TeXinfo")
                          ("\\.c$"              . "C")
                          ("\\.cc$"             . "C++")
                          ("\\.h$"              . "C Header")
                          ("\\.el$"             . "Emacs Lisp")
                          ("[Mm]akefile"        . "Makefile")
                          ("\\.sh$"             . "Sh")
                          ("\\.pl$"             . "Perl")))

(setq auto-insert-type-alist '(("TeXinfo"    . "texinfo-insert.texi")
                               ("C"          . "c-insert.c")
                               ("C Header"   . "h-insert.h")
                               ("C++"        . "c++-insert.cc")
                               ("Emacs Lisp" . "elisp-insert.el")
                               ("Makefile"   . "makefile.inc")
                               ("Perl"       . "perl-insert.pl")
                               ("Sh"         . "sh-insert.sh")))

(add-to-list 'auto-insert-path '"~/documents/Templates/")

;; Don't auto-insert into AucTeX style .els
(defadvice TeX-auto-store (around no-auto-insert activate)
  "Ensure auto-insert is deactivated"
  (let ((auto-insert-automatically nil))
    ad-do-it))
(message "Auto-Insert initialised!")

;:*=======================
;:* My git shit
(require 'sy-git)
(require 'git)

;:*======================
;:* Emacs Lisp List
(defvar sxell-initialised-flag)
(defvar sxell-download-directory)
(when (and (featurep '(and sxemacs postgresql))
           (fboundp 'ffi-defun))
  (require 'sxell)
  (setq sxell-initialised-flag t
        sxell-download-directory
        (file-name-as-directory (expand-file-name "download/SXEmacs"
                                                  (user-home-directory)))))
;:*======================
;:* EasyPG
(require 'epa-setup)

(defun sy-epa-export-key ()
  "Wrapper for `epa-export-keys' to export ASCII armoured keys."
  (interactive)
  (let ((epa-armor t))
    (call-interactively #'epa-export-keys)))

(define-key epa-key-list-mode-map [?O] #'sy-epa-export-key)

;:*=======================
;:* Howm thing. (this needs mule, but that is default so no biggie)
(require 'howm)

(setq
 howm-directory (file-name-as-directory
                 (expand-file-name "howm" user-init-directory))
 howm-keyword-file (expand-file-name "howm-keys" user-init-directory)
 howm-history-file (expand-file-name "howm-history" user-init-directory))

;; howm has the unfortunate name that ends in `wm' which is what
;; winmgr-mode uses, so nuke winmgr-mode from auto-mode-alist
(remove-alist 'auto-mode-alist "\\.[^/]*wm2?\\(?:rc\\)?\\'")

;; The howm people are nuts, they bind C-h to scroll-down
;; Get rid of it and replace with DEL and BACKSPACE
(define-key howm-menu-mode-map "\C-h" nil)
(define-key howm-menu-mode-map [delete] #'scroll-down)
(define-key howm-menu-mode-map [backspace] #'scroll-down)
(define-key riffle-summary-mode-map "\C-h" nil)
(define-key riffle-summary-mode-map [delete] #'scroll-other-window-down)
(define-key riffle-summary-mode-map [backspace] #'scroll-other-window-down)
(define-key riffle-contents-mode-map "\C-h" nil)
(define-key riffle-contents-mode-map [delete] #'scroll-down)
(define-key riffle-contents-mode-map [backspace] #'scroll-down)

;; Add a binding to show the active todo list
(global-set-key [(control ?c) ?t] #'howm-list-active-todo)

;; Another problem with howm... it fucks up window configuration
;; Advice time!
(defadvice howm-keyword-search (before howm-save-kw (&rest args) activate)
 "Save window configuration before viewing howm buffers."
 (window-configuration-to-register ?h))

(defadvice howm-list-grep-fixed (before howm-save-win1 (&rest args) activate)
 "Save window configuration before viewing howm buffers."
 (window-configuration-to-register ?h))

(defadvice howm-list-grep (before howm-save-win (&rest args) activate)
 "Save window configuration before viewing howm buffers."
 (window-configuration-to-register ?h))

(defadvice howm-list-todo (before howm-save-win (&rest args) activate)
 "Save window configuration before viewing howm buffers."
 (window-configuration-to-register ?h))

(defadvice howm-list-active-todo (before howm-save-win (&rest args) activate)
 "Save window configuration before viewing howm buffers."
 (window-configuration-to-register ?h))

(defadvice riffle-kill-buffer (after howm-restore-win (&rest args) activate)
  "Restore the original window configuration."
  (jump-to-register ?h))

;; howm fucks up font-lock'ing like you wouldn't believe, adding a
;; call to `turn-on-font-lock' here at least restores a certain level
;; of normalcy.
(defun turn-on-howm-mode ()
  (turn-on-font-lock)
  (howm-mode 1))

(defun turn-off-howm-mode ()
  (howm-mode 0)
  (font-lock-mode))

;; Turn it on where I need it
(add-hook 'lisp-interaction-mode-hook #'turn-on-howm-mode)
(add-hook 'text-mode-hook #'turn-on-howm-mode)
(add-hook 'latex-mode-hook #'turn-on-howm-mode)
(add-hook 'c-mode-hook #'turn-on-howm-mode)
(add-hook 'sh-mode-hook #'turn-on-howm-mode)
;; You gotta be fooking kidding me, this prevents lisp-initd.el from
;; compiling the generated .el (moved to init.el)
;; (add-hook 'emacs-lisp-mode-hook #'turn-on-howm-mode)

;; Turn it off where I don't
;; I actually would love to have howm in all of these modes, but I
;; cannot get the font-locking working properly with it on
(add-hook 'html-mode-hook #'turn-off-howm-mode)
(add-hook 'texinfo-mode-hook #'turn-off-howm-mode)
(add-hook 'message-mode-hook #'turn-off-howm-mode)
(add-hook 'change-log-mode-hook #'turn-off-howm-mode)

;:*=====================
;:* snap!
;; save/load snapshot of application to/from text
;; Usage:

;; (1) M-x snap-record on application, e.g. Wanderlust.
;; (2) Yank (C-y) on any buffer, e.g. *scratch* or ~/memo.txt.
;; (3) M-x snap-play on yanked text ==> snapshot (1) is restored.
(require 'snap)
(global-set-key [(hyper ?s) ?r] #'snap-record)

;; env var trickery.
(setq snap-abbreviate-environment-variables
      '("EMCHAT" "JAVA_HOME" "EL" "XPKGS" "MPKGS" "PKGS" "QTDIR"
        "BLDS" "SXESITE" "SXEWD" "SYdrive" "SYdrop" "HOME"))

(defadvice snap-abbreviate-file-name (around env-var (raw-path) activate)
  ad-do-it
  (let ((path (expand-file-name raw-path))
        (rules (mapcar #'(lambda (var)
                           (let ((val (getenv var)))
                             (and val
                                  (cons (concat "^" (regexp-quote val))
                                        (format "${%s}" var)))))
                       snap-abbreviate-environment-variables)))
    (mapc #'(lambda (r)
              (when (and r (string-match (car r) path))
                (setq ad-return-value
                      (replace-regexp-in-string (car r) (cdr r) path))))
          (reverse rules))))

;; Bookmark extras
(eval-after-load "bookmark"
  (progn
    (ad-enable-advice 'bookmark-buffer-file-name 'around 'with-snap)
    (ad-enable-advice 'bookmark-jump-noselect 'around 'with-snap)))

;; ffap extras
(setq ffap-url-regexp snap-ffap-url-regexp)
(setq ffap-url-fetcher snap-ffap-url-fetcher)

;:*=======================
;:* ElDoc (handy thingy dingy for lisp programming)
;;  displays function args and var doc strings in echo area
;(setq eldoc-use-idle-timer-p nil)
;(autoload #'turn-on-eldoc-mode "eldoc" nil t)
;(add-hook 'emacs-lisp-mode-hook #'turn-on-eldoc-mode)
;(add-hook 'lisp-interaction-mode-hook #'turn-on-eldoc-mode)

;:*=======================
;:* Man pages
(require 'man)

;; You can't follow xrefs via keyboard, so...
(defun sy:Manual-follow-xref-kbd ()
  "Invoke `manual-entry' on the cross-reference at point."
  (interactive)
  (let* ((ext (extent-at (point)))
         (data (and ext (extent-property ext 'man))))
    (if (eq (car-safe data) 'Manual-follow-xref)
        (eval data)
      (error 'search-failed "no manual cross-reference there."))
    (or (manual-entry (extent-string ext))
        ;; Couldn't find it, try other sections.
        (and (string-match "[ \t]*([^)]+)\\'" (extent-string ext))
             (progn
               (message "No entries found for %s; checking other sections..."
                        (extent-string ext))
               (manual-entry
                (substring (extent-string ext) 0 (match-beginning 0))
                nil t))))))

(define-key Manual-mode-map [(control return)] #'sy:Manual-follow-xref-kbd)
(define-key Manual-mode-map [button1] #'Manual-follow-xref)

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
(message "packages loaded")
Created with SXEmacs Valid XHTML 1.0 Transitional!
Copyright © 2020 Steve Youngs
Verbatim copying and distribution is permitted in any medium, providing this notice is preserved.
Last modified: Sat Apr 18 21:42:24 AEST 2020