Org mode: Problems with folding (no matching item found on current line) - emacs

I'm having a weird problem with Emacs (doom-emacs) on macOS (brew cask emacs-mac-spacemacs-icon): I sporadically cannot fold a heading. I can unfold it, then its children are shown, however, when I try to fold it I get the message "No matching item found on the current line". Sometimes it works again after changing to another application and tabbing back, the the message line shows "FOLDED" and "CHILDREN" when I press the Tab key.
It also works in some org files, but not in others. I don't know what's differen between them.
I just realized that when I have an inactive timestamp as a heading, pressing tab once shows the children but pressing it again just jumps between the brackets...
Here is my configuration:
;; Doom exposes five (optional) variables for controlling fonts in Doom. Here
;; are the three important ones:
;;
;; + `doom-font'
;; + `doom-variable-pitch-font'
;; + `doom-big-font' -- used for `doom-big-font-mode'; use this for
;; presentations or streaming.
;;
;; They all accept either a font-spec, font string ("Input Mono-12"), or xlfd
;; font string. You generally only need these two:
(setq doom-font (font-spec :family "Meslo LG M for Powerline"
:size 12))
;; There are two ways to load a theme. Both assume the theme is installed and
;; available. You can either set `doom-theme' or manually load a theme with the
;; `load-theme' function. This is the default:
(setq doom-theme 'doom-gruvbox)
;; Enable visual line mode per default for text files
(add-hook! 'text-mode-hook 'turn-on-visual-line-mode)
;; Enable org-autolist
(add-hook 'org-mode-hook (lambda () (org-autolist-mode)))
;; Org mode configuration
(setq org-directory "~/org")
(setq org-default-clock-file (concat org-directory "/clock.org"))
(after! org
(setq org-agenda-files (list org-directory))
(setq org-default-notes-file (concat org-directory "/inbox.org"))
(setq org-task-file (concat org-directory "/tasks.org"))
(setq org-log-into-drawer t)
(setq org-log-done nil)
(setq org-image-actual-width (/ (display-pixel-width) 3))
(setq org-todo-keywords
'((sequence "TODO(t)" "IN-PROGRESS(i!)" "WAITING(#w)" "|"
"DONE(d!)" "CANCELED(#c)")))
(setq org-todo-keyword-faces
'(
("TODO" . (:foreground "#fb4933" :weight bold))
("IN-PROGRESS" . (:foreground "#fabd2f" :weight bold))
("WAITING" . (:foreground "#fe8019" :weight bold))
("DONE" . (:foreground "#8ec07c" :weight bold))
("CANCELED" . (:foreground "#83a598" :weight bold))
)
)
(setq org-capture-templates
`(("r" "Weekly report" entry (file+headline org-default-clock-file "Clock")
,(concat "** Woche %<%V>\n"
"*** Gesamt\n"
"#+BEGIN: clocktable :scope agenda :maxlevel 20 :block 2020-W%<%V> :step week :stepskip0 t\n"
"#+END:\n"
"*** Tage\n"
"#+BEGIN: clocktable :scope agenda :maxlevel 20 :block 2020-W%<%V> :step day :stepskip0 t\n"
"#+END:"
)
)))
(setq org-startup-indented t)
(setq org-clock-persist 'history)
(org-clock-persistence-insinuate)
(setq org-duration-format (quote h:mm))
(setq org-refile-targets '((org-agenda-files :maxlevel . 10)))
(setq org-goto-interface 'outline-path-completion)
(defvar org-created-property-name "CREATED"
"The name of the org-mode property that stores the creation date of the entry")
(defun org-set-created-property (&optional active NAME)
"Set a property on the entry giving the creation time.
By default the property is called CREATED. If given the `NAME'
argument will be used instead. If the property already exists, it
will not be modified."
(interactive)
(let* ((created (or NAME org-created-property-name))
(fmt (if active "<%s>" "[%s]"))
(now (format fmt (format-time-string "%Y-%m-%d %a %H:%M"))))
(unless (org-entry-get (point) created nil)
(org-set-property created now))))
;; Key mappings
(map! :leader
(:prefix ("o" . "org")
:desc "Goto" "g" 'org-goto
:desc "Insert inactive timestamp" "!" 'org-time-stamp-inactive
:desc "Update dynamic block" "u" 'org-dblock-update
:desc "Todo list" "t" 'org-todo-list
:desc "Agenda" "a" 'org-agenda
:desc "Tag search" "m" 'org-tags-view
:desc "Search org headlines" "h" #'+default/org-notes-headlines
:desc "Search org files" "s" #'+default/org-notes-search
:desc "Refile" "r" 'org-refile
:desc "Browse notes" "f" #'+default/browse-notes
:desc "Search notes for symbol" "." #'+default/search-notes-for-symbol-at-point
:desc "Org capture" "n" #'org-capture
(:prefix ("c" . "clock")
:desc "Clock in" "i" 'org-clock-in
:desc "Clock out" "o" 'org-clock-out
:desc "Jump to last clock" "l" (lambda () (interactive) (setq current-prefix-arg '(4)) (org-clock-goto))
:desc "Jump to active clock" "j" 'org-clock-goto)
(:prefix ("p" . "properties")
:desc "Set CREATED property" "c" 'org-set-created-property)
))
)
;; This determines the style of line numbers in effect. If set to `nil', line
;; numbers are disabled. For relative line numbers, set this to `relative'.
(setq display-line-numbers-type t)
;; Key unmappings
(map! :leader "n" nil)
(map! :leader "o" nil)

i had this problem with doom, due to a keybinding conflict with
evil-jump-item. I fixed it by rebinding tab:
(map! :after evil-org
:map org-mode-map
:desc "org-cycle" :n [tab] #'org-cycle)

Related

Update linum and linum-relative background on color theme change in emacs/spacemacs

Trying to get the line numbering right aligned with a separator space and the same background color as the line highlighting in Spacemacs was quite complicated. Specialy when it came to do both at the same time in linum and linum-relative.
I don't know if this code is ok, but it manages so far:
(defun dotspacemacs/user-config ()
"Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration. You are free to put any user code."
(global-linum-mode t)
(unless window-system
(add-hook 'linum-before-numbering-hook
(lambda ()
(setq-local my-linum-format-fmt
(let ((w (length (number-to-string
(count-lines (point-min) (point-max))))))
(concat "%" (number-to-string w) "d"))))
(set-face-attribute 'linum nil
:background (face-background 'hl-line nil t))))
(defface my-linum-hl
`((t :inherit linum :background ,(face-background 'hl-line nil t)))
"Face for the current line number."
:group 'linum)
(defun my-linum-format-func (line)
(concat
(propertize (format my-linum-format-fmt line) 'face 'my-linum-hl)
(propertize " " 'face 'my-linum-hl)))
(unless window-system
(setq linum-format 'my-linum-format-func))
;; linum-relative
(linum-relative-toggle)
(unless window-system
(setq-local my-linum-relative-format-fmt
(let ((w (length (number-to-string
(count-lines (point-min) (point-max))))))
(concat "%" (number-to-string w) "s "))))
(unless window-system
(setq linum-relative-format my-linum-relative-format-fmt))
)
Problem is: The numbers background color don't change to the correct one when I change the theme while inside Emacs. The color remains the same. How do I make emacs update the linum and linum-relative background color after a color theme change?

How to display text with different colors in mode-line

I want to display parts of my mode line with different colors but it isn't working as expected and I can't find a good web reference for this. I can change the text to bold or italic but not change the colors as required.
The simplest possible example is to display a simple mode line with the buffer-file-name in white rather than the default face color.
(custom-set-variables
'(mode-line-format
(quote
("%e" mode-line-front-space
"[" mode-name "] %l:%i"
"\t"
propertize buffer-file-name 'font-lock-face '(:foreground "white")))))
Thanks to legosica for pointing out that I should have included other examples of what I've tried ...
Replacing 'font-lock-face with 'face:
propertize buffer-file-name 'face '(:foreground "white")))))
Follow Up
Thanks to TacticalCoder I now have exactly what I want - multiple fonts and colours in my modeline. The reason why setting 'face '(:foreground "white") didn't work is that it needed to be wrapped in '(:eval ...).
I ended up with this ...
(setq-default mode-line-format
(list
mode-line-front-space ; +-- just like in the default mode-line-format
'(:eval (propertize (concat "\t[" mode-name "] %l:%i\t") 'face '(:foreground "black" :height 0.9 :weight normal)
'help-echo (buffer-file-name)))
'(:eval (propertize (file-name-directory buffer-file-name) 'face 'info-title-4
'help-echo (buffer-file-name)))
'(:eval (propertize (file-name-nondirectory buffer-file-name) 'face 'info-title-3
'help-echo (buffer-file-name)))
))
Combined with ...
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(info-title-3 ((t (:inherit info-title-4 :foreground "white" :height 1.2))))
'(info-title-4 ((t (:inherit info-title-4 :foreground "black"))))
'(mode-line ((t (:background "#6483af" :foreground "#001122" :box (:line-width 3 :color "#6483af") :weight ultra-bold :height 118 :family "Monospace")))))
... I get a nice simple mode-line that demonstrates most of what I want. More work to do but thanks to TacticalCoder, I'm back on track.
Here's a tiny part of the custom modeline I'm using (I don't remember where I found it), modified as you asked to show the buffer name in another color. In this example I'm using font-lock-warning-face (which is 'red' in my color scheme):
This is not a complete modeline by any mean:
(setq-default mode-line-format
(list
mode-line-front-space ; +-- just like in the default mode-line-format
mode-line-mule-info ; |
mode-line-client ; |
;; the buffer name; the file name as a tool tip if you hover the mouse on it
'(:eval (propertize "%b " 'face 'font-lock-warning-face
'help-echo (buffer-file-name)))
'(:eval (propertize (if overwrite-mode "OVERWRITE" "")
'face 'font-lock-warning-face
'help-echo (concat "Buffer is in "
(if overwrite-mode "overwrite" "insert") " mode")))
"%-" ; fill what's left with '-'
))
Does that work for you? I did also put the part where OVERWRITE appears in font-lock-warning-face in case you turn overwrite on (I kinda hate being in overwrite mode, so I want it to be very obvious).

Highlight which of the file names in emacs buffer are missing

In GNU Emacs, I could use something like a hypothetical "flyexist.el" - I have a buffer with absolute (Unix) file names in it (plus some additional text around them). Most of those files exist, but some are missing. I would like to run a function that highlights me the missing files (maybe with a red overlay). This function would need to figure out which of the text in the buffer looks like a file name (some false positives are okay) and then work on it with file-exists-p.
For example, assume that my buffer contains
Some random text mentioning /file/that/does/exist.txt,
some more random text, and a /file/that/does/not-exist.txt
I want to have the second file highlighted.
Does something like this exist already?
I am new to emacs hacking... Here is my "minor-mode" version.
(defvar filehi-path-re "\\([/$][[:alnum:]$-_.]+\\)+"
"Regexp used for path matching.")
(defface filehi-file-existing
'((t (:foreground "White" :background "Green")))
"Face for existing files.")
(defface filehi-file-missing
'((t (:foreground "Yellow" :background "Red")))
"Face for missing files.")
(defun filehi-check-and-highlight (start end)
"Check if substring is existing file path and highlight it."
(remove-overlays start end 'name 'filehi-highlight)
(let ((overlay (make-overlay start end)))
(overlay-put overlay 'name 'filehi-highlight)
(overlay-put overlay 'face (if (file-exists-p (substitute-in-file-name
(buffer-substring start end)))
'filehi-file-existing
'filehi-file-missing))))
(defun filehi-highlight-file-paths (&optional start end _ignore)
"Run through the buffer and highliht file paths."
(save-excursion
(save-match-data ; fixes problem with dabbrev (and may be more...)
(remove-overlays (point-min) end 'name 'filehi-highlight)
(let ((prev-end (point-min)))
(goto-char (point-min)) ; FIXME use something like greedy
; search-backward
(while (and (<= (point) end)
(re-search-forward filehi-path-re nil t))
(filehi-check-and-highlight (match-beginning 0) (match-end 0)))))))
(define-minor-mode filehi-mode
"Minor mode for highlighting existing file paths.
May conflict with other modes..."
nil " Filehi" nil
(if filehi-mode
(progn ; enable mode
(make-local-hook 'after-change-functions)
(filehi-highlight-file-paths (point-min) (point-max))
(add-hook 'after-change-functions 'filehi-highlight-file-paths nil t))
; disable mode
(remove-hook 'after-change-functions 'filehi-highlight-file-paths t)
(remove-overlays (point-min) (point-max) 'name 'filehi-highlight)))
Try with this (you have to trigger it manually though, or incorporate it into some other periodical routine):
(defun x-mark-missing-files ()
(interactive)
(save-excursion
(while (search-forward-regexp "~?/[A-Za-z./-]+")
(when (not (file-exists-p (match-string 0)))
(overlay-put
(make-overlay (match-beginning 0) (match-end 0))
'face '(:background "red"))))))
Play a little with the filename regexp to get it right how you want it.

Can't seem to get rid of Ctrl-x Ctrl-z Key Binding in Emacs for minimizing window ('suspend-frame)

I keep trying to get rid of this keybinding but setting it to nil or 'undo which would be fine with no luck. I am not sure why it even gets set to C-x C-z in the first place. I wouldn't even mind permanently removing the suspend-frame command if that would provide a solution.
Here is my .emacs file if it helps:
;;Style files and multi-file documents
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(setq inhibit-splash-screen t)
;; Use PDF mode by default
(setq-default TeX-PDF-mode t)
(setq TeX-save-query nil)
(global-auto-revert-mode t)
(global-set-key "\C-x C-z" nil)
(global-set-key "\C-z" nil)
;;Abbreviation mode and settings
(add-hook 'text-mode-hook (lambda () (abbrev-mode 1)))
(setq save-abbrevs t)
(quietly-read-abbrev-file)
;;Reftex and then turn on for Auctex
(require 'reftex)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
;;Enable preview latex
(load "preview-latex.el" nil t t)
;; For line numbers loading
(require 'linum)
(setq linum-format "%d ")
(global-linum-mode 1)
;; ===== Set the highlight current line minor mode =====
(global-hl-line-mode 1)
;; ===== Set standard indent to 2 rather that 4 ====
;;(setq standard-indent 2)
;; ========== Enable Line and Column Numbering ==========
;; Show line-number in the mode line
(line-number-mode 1)
;; Show column-number in the mode line
(column-number-mode 1)
;; ========== Force emacs to use tabs ==================
;; Turn on tabs
;;(setq indent-tabs-mode t)
;;(setq-default indent-tabs-mode t)
;; Bind the TAB key
;;(global-set-key (kbd "TAB") 'self-insert-command)
;; Set the tab width
;;(setq default-tab-width 4)
;;(setq tab-width 4)
;;(setq c-basic-indent 4)
(setq outline-minor-mode 1)
; Outline-minor-mode key map
(define-prefix-command 'cm-map nil "Outline-")
; HIDE
(define-key cm-map "q" 'hide-sublevels) ; Hide everything but the top-level headings
(define-key cm-map "t" 'hide-body) ; Hide everything but headings (all body lines)
(define-key cm-map "o" 'hide-other) ; Hide other branches
(define-key cm-map "c" 'hide-entry) ; Hide this entry's body
(define-key cm-map "l" 'hide-leaves) ; Hide body lines in this entry and sub-entries
(define-key cm-map "d" 'hide-subtree) ; Hide everything in this entry and sub-entries
; SHOW
(define-key cm-map "a" 'show-all) ; Show (expand) everything
(define-key cm-map "e" 'show-entry) ; Show this heading's body
(define-key cm-map "i" 'show-children) ; Show this heading's immediate child sub-headings
(define-key cm-map "k" 'show-branches) ; Show all sub-headings under this heading
(define-key cm-map "s" 'show-subtree) ; Show (expand) everything in this heading & below
; MOVE
(define-key cm-map "u" 'outline-up-heading) ; Up
(define-key cm-map "n" 'outline-next-visible-heading) ; Next
(define-key cm-map "p" 'outline-previous-visible-heading) ; Previous
(define-key cm-map "f" 'outline-forward-same-level) ; Forward - same level
(define-key cm-map "b" 'outline-backward-same-level) ; Backward - same level
(global-set-key "\M-o" cm-map)
;;Display recent files
(require 'recentf)
(recentf-mode 1)
(setq recentf-max-menu-items 50)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)
;; Allows hiding and folding
(defun turn-on-outline-minor-mode ()
(outline-minor-mode 1))
;;Flymake mode to check syntax on the fly
;;(require 'flymake)
;;(add-hook 'find-file-hook 'flymake-find-file-hook)
;;(defun flymake-get-tex-args (file-name)
;; (list "pdflatex" (list "-file-line-error" "-draftmode" "-interaction=nonstopmode" file-name)))
;;Fly spell mode
(dolist (hook '(text-mode-hook))
(add-hook hook (lambda () (flyspell-mode 1))))
(require 'tabbar)
; turn on the tabbar
(tabbar-mode t)
; define all tabs to be one of 3 possible groups: “Emacs Buffer”, “Dired”,
;“User Buffer”.
(defun tabbar-buffer-groups ()
"Return the list of group names the current buffer belongs to.
This function is a custom function for tabbar-mode's tabbar-buffer-groups.
This function group all buffers into 3 groups:
Those Dired, those user buffer, and those emacs buffer.
Emacs buffer are those starting with “*”."
(list
(cond
((string-equal "*" (substring (buffer-name) 0 1))
"Emacs Buffer"
)
((eq major-mode 'dired-mode)
"Dired"
)
(t
"User Buffer"
)
)))
(setq tabbar-buffer-groups-function 'tabbar-buffer-groups)
(define-key global-map [(super j)] 'tabbar-backward)
(define-key global-map [(super k)] 'tabbar-forward)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(LaTeX-indent-level 4)
'(LaTeX-item-indent -2)
'(TeX-PDF-mode t)
'(TeX-auto-save t)
'(TeX-brace-indent-level 4)
'(TeX-command-list (quote (("doall" "%`%l%(mode)%' %t && bibtex %s && %`%l%(mode)%' %t && %`%l%(mode)%' %t && %V" TeX-run-TeX nil t :help "Run LaTeX BibTeX LaTeX LaTeX View") ("ebibno" "%`%l%(mode)%' %t && %`%l%(mode)%' %t && %`%l%(mode)%' %t && %V" TeX-run-TeX nil t :help "Run LaTeX View") ("TeX" "%(PDF)%(tex) %`%S%(PDFout)%(mode)%' %t" TeX-run-TeX nil (plain-tex-mode texinfo-mode ams-tex-mode) :help "Run plain TeX") ("LaTeX" "%`%l%(mode)%' %t" TeX-run-TeX nil (latex-mode doctex-mode) :help "Run LaTeX") ("Makeinfo" "makeinfo %t" TeX-run-compile nil (texinfo-mode) :help "Run Makeinfo with Info output") ("Makeinfo HTML" "makeinfo --html %t" TeX-run-compile nil (texinfo-mode) :help "Run Makeinfo with HTML output") ("AmSTeX" "%(PDF)amstex %`%S%(PDFout)%(mode)%' %t" TeX-run-TeX nil (ams-tex-mode) :help "Run AMSTeX") ("ConTeXt" "texexec --once --texutil %(execopts)%t" TeX-run-TeX nil (context-mode) :help "Run ConTeXt once") ("ConTeXt Full" "texexec %(execopts)%t" TeX-run-TeX nil (context-mode) :help "Run ConTeXt until completion") ("BibTeX" "bibtex %s" TeX-run-BibTeX nil t :help "Run BibTeX") ("View" "%V" TeX-run-discard-or-function t t :help "Run Viewer") ("Print" "%p" TeX-run-command t t :help "Print the file") ("Queue" "%q" TeX-run-background nil t :help "View the printer queue" :visible TeX-queue-command) ("File" "%(o?)dvips %d -o %f " TeX-run-command t t :help "Generate PostScript file") ("Index" "makeindex %s" TeX-run-command nil t :help "Create index file") ("Check" "lacheck %s" TeX-run-compile nil (latex-mode) :help "Check LaTeX file for correctness") ("Spell" "(TeX-ispell-document \"\")" TeX-run-function nil t :help "Spell-check the document") ("Clean" "TeX-clean" TeX-run-function nil t :help "Delete generated intermediate files") ("Clean All" "(TeX-clean t)" TeX-run-function nil t :help "Delete generated intermediate and output files") ("Other" "" TeX-run-command t t :help "Run an arbitrary command"))))
'(TeX-debug-warnings t)
'(TeX-master nil)
'(TeX-source-correlate-method (quote synctex))
'(TeX-source-correlate-mode t)
'(TeX-source-correlate-start-server t)
'(TeX-view-program-list (quote (("Okular" "okular --unique %o#src:%n%b"))))
'(TeX-view-program-selection (quote (((output-dvi style-pstricks) "dvips and gv") (output-dvi "xdvi") (output-pdf "Okular") (output-html "xdg-open"))))
'(column-number-mode t)
'(cua-enable-cua-keys t)
'(cua-mode t nil (cua-base)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "white" :foreground "black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 98 :width normal :foundry "unknown" :family "DejaVu Sans")))))
;;Switch to last recent buffer used with F11 or ShiftF11
(when (require 'bubble-buffer nil t)
(global-set-key [f11] 'bubble-buffer-next)
(global-set-key [(shift f11)] 'bubble-buffer-previous))
(setq bubble-buffer-omit-regexp "\\(^ .+$\\|\\*Messages\\*\\|*compilation\\*\\|\\*.+output\\*$\\|\\*TeX Help\\*$\\|\\*vc-diff\\*\\|\\*Occur\\*\\|\\*grep\\*\\|\\*cvs-diff\\*\\)")
(global-set-key "\M-n" (lambda () (interactive) (scroll-up 6)) )
(global-set-key "\M-p" (lambda () (interactive) (scroll-down 6)) )
(defun sfp-page-down (&optional arg)
(interactive "^P")
(setq this-command 'next-line)
(next-line
(- (window-text-height)
next-screen-context-lines)))
(put 'sfp-page-down 'isearch-scroll t)
(put 'sfp-page-down 'CUA 'move)
(defun sfp-page-up (&optional arg)
(interactive "^P")
(setq this-command 'previous-line)
(previous-line
(- (window-text-height)
next-screen-context-lines)))
(put 'sfp-page-up 'isearch-scroll t)
(put 'sfp-page-up 'CUA 'move)
(set-face-attribute 'default nil :height 100)
(setq cua-mode t)
(require 'latex)
(when (require 'browse-kill-ring nil 'noerror)
(browse-kill-ring-default-keybindings))
(global-set-key "\C-cy" '(lambda ()
(interactive)
(popup-menu 'yank-menu)))
(setq x-select-enable-clipboard t)
(define-key LaTeX-mode-map (read-kbd-macro "C-c C-a")
(lambda ()
(interactive)
(TeX-save-document (TeX-master-file))
(TeX-command "Doall" 'TeX-master-file -1)))
;;(autoload 'whizzytex-mode "whizzytex"
;;"WhizzyTeX, a minor-mode WYSIWYG environment for LaTeX" t)
;;Set up extra key-bindings for reftex
;;(setq reftex-extra-bindings t)
(defun my-latex-setup ()
(defun latex-word-count ()
(interactive)
(let* ((this-file (buffer-file-name))
(word-count
(with-output-to-string
(with-current-buffer standard-output
(call-process "texcount" nil t nil "-inc" "-brief" this-file)))))
(string-match "\n$" word-count)
(message (replace-match "" nil nil word-count))))
(define-key LaTeX-mode-map "\C-cw" 'latex-word-count)
(define-key LaTeX-mode-map "\C-xw" 'latex-word-count))
(add-hook 'LaTeX-mode-hook 'my-latex-setup t)
(global-set-key "\C-x C-z" 'undo)
(add-hook 'text-mode-hook (lambda ()
(local-set-key (kbd "C-c C-.")
(lambda () (interactive) (search-forward "." nil t)))))
(add-hook 'text-mode-hook (lambda ()
(local-set-key (kbd "C-c C-,")
(lambda () (interactive) (search-backward "." nil t)))))
(require 'ido)
(ido-mode t)
(fset 'yes-or-no-p 'y-or-n-p)
;(global-set-key (kbd "C-?") 'hippie-expand) not working
;(setq hippie-expand-try-functions-list '(try-expand-dabbrev try-expand-dabbrev-all-buffers try-expand-dabbrev-from-kill try-complete-file-name-partially try-complete-file-name try-expand-all-abbrevs try-expand-list try-expand-line try-complete-lisp-symbol-partially try-complete-lisp-symbol))
;;Save place in files between sessions
(require 'saveplace)
(setq-default save-place t)
;;Added windows.el configuration
(require 'windows)
;; -- load the saved windows automatically on boot
(add-hook 'window-setup-hook 'resume-windows)
;; -- use this command to quit and save your setup
(define-key ctl-x-map "C" 'see-you-again)
;; -- set up window saving !! Place at end of .emacs file
(win:startup-with-window)
Your string representation of C-x C-z needs adjusting. Try either of the following:
(global-set-key "\C-x\C-z" nil)
(global-set-key (kbd "C-x C-z") nil)
Or you can disable the suspend-frame command:
(put 'suspend-frame 'disabled t)
Try this:
(global-unset-key "\C-z")
(global-unset-key "\C-x\C-z")

Highlighting correctly in an emacs major mode

I am developing an emacs major mode for a language (aka mydsl). However, using the techniques on xahlee's site doesn't seem to be working for some reason (possibly older emacs dialect..)
The key issues I am fighting with are (1) highlighting comments is not working and (2), the use of regexp-opt lines is not working.
I've reviewed the GNU manual and looked over cc-mode and elisp mode... those are significantly more complicated than I need.
;;;Standard # to newline comment
;;;Eventually should also have %% to %% multiline block comments
(defun mydsl-comment-dwim (arg)
"comment or uncomment"
(interactive "*P")
(require 'newcomment)
(let
((deactivate-mark nil)
(comment-start "#")
(comment-end "")
comment-dwim arg)))
(defvar mydsl-events
'("reservedword1"
"reservedword2"))
(defvar mydsl-keywords
'("other-keyword" "another-keyword"))
;;Highlight various elements
(setq mydsl-hilite
'(
; stuff between "
("\"\\.\\*\\?" . font-lock-string-face)
; : , ; { } => # $ = are all special elements
(":\\|,\\|;\\|{\\|}\\|=>\\|#\\|$\\|=" . font-lock-keyword-face)
( ,(regexp-opt mydsl-keywords 'words) . font-lock-builtin-face)
( ,(regexp-opt mydsl-events 'words) . font-lock-constant-face)
))
(defvar mydsl-tab-width nil "Width of a tab for MYDSL mode")
(define-derived-mode mydsl-mode fundamental-mode
"MYDSL mode is a major mode for editing MYDSL files"
;Recommended by manual
(kill-all-local-variables)
(setq mode-name "MYDSL script")
(setq font-lock-defaults '((mydsl-hilite)))
(if (null mydsl-tab-width)
(setq tab-width mydsl-tab-width)
(setq tab-width default-tab-width)
)
;Comment definitions
(define-key mydsl-mode-map [remap comment-dwim] 'mydsl-comment-dwim)
(modify-syntax-entry ?# "< b" mydsl-mode-syntax-table)
(modify-syntax-entry ?\n "> b" mydsl-mode-syntax-table)
;;A gnu-correct program will have some sort of hook call here.
)
(provide 'mydsl-mode)
You have a couple of syntactic problems in your code, but you got it nearly correct. Here's my edited version which appears to do the right thing for a buffer in mydsl-mode:
; No changes to the simple vars
(defvar mydsl-events
'("reservedword1"
"reservedword2"))
(defvar mydsl-keywords
'("other-keyword" "another-keyword"))
;; I'd probably put in a default that you want, as opposed to nil
(defvar mydsl-tab-width nil "Width of a tab for MYDSL mode")
;; Two small edits.
;; First is to put an extra set of parens () around the list
;; which is the format that font-lock-defaults wants
;; Second, you used ' (quote) at the outermost level where you wanted ` (backquote)
;; you were very close
(defvar mydsl-font-lock-defaults
`((
;; stuff between "
("\"\\.\\*\\?" . font-lock-string-face)
;; ; : , ; { } => # $ = are all special elements
(":\\|,\\|;\\|{\\|}\\|=>\\|#\\|$\\|=" . font-lock-keyword-face)
( ,(regexp-opt mydsl-keywords 'words) . font-lock-builtin-face)
( ,(regexp-opt mydsl-events 'words) . font-lock-constant-face)
)))
(define-derived-mode mydsl-mode fundamental-mode "MYDSL script"
"MYDSL mode is a major mode for editing MYDSL files"
;; fundamental-mode kills all local variables, no need to do it again
(setq mode-name "MYDSL script")
;; you again used quote when you had '((mydsl-hilite))
;; I just updated the variable to have the proper nesting (as noted above)
;; and use the value directly here
(setq font-lock-defaults mydsl-font-lock-defaults)
;; when there's an override, use it
;; otherwise it gets the default value
(when mydsl-tab-width
(setq tab-width mydsl-tab-width))
;; for comments
;; overriding these vars gets you what (I think) you want
;; they're made buffer local when you set them
(setq comment-start "#")
(setq comment-end "")
(modify-syntax-entry ?# "< b" mydsl-mode-syntax-table)
(modify-syntax-entry ?\n "> b" mydsl-mode-syntax-table)
;;A gnu-correct program will have some sort of hook call here.
)
(provide 'mydsl-mode)