How to setup custom font in emacs? - emacs

I would like to use Proggy font for my programming in Emacs.
How can I set it up?
Please note it is a bitmap font.

you can use:
(set-default-font "ProggyClean")
which is deprecated and should be
(set-frame-font "ProggyClean")
from Emacs 23.1 on in you .emacs or you can do M-x: customize-face: default and set ProggyClean as "Font Family".

Just sticking set-default-font in your .emacs won't work across multiple frames - each new frame will go back to the old default. Customize does work with multiple frames, but I've never managed to get it to work properly across different platforms (and different platforms have different font settings even for the same font).
So! This is what I've got in my .emacs. It works in linux, win32 and cygwin, and works with multiple frames (and hence emacs client).
(defconst win32p (eq system-type 'windows-nt) "Are we running on a Windows system?")
(defconst cygwinp (eq system-type 'cygwin) "Are we running on Cygwin?")
(defconst linuxp (or (eq system-type 'gnu/linux) (eq system-type 'linux)) "Are we running on Linux?")
;;font setups
(defvar vsc-little-font "" "*My lovely little font")
(when linuxp
(setq vsc-little-font "ProggyTinyTT-8"))
(when cygwinp
(setq vsc-little-font "ProggyTinyTT-16"))
(when win32p
(setq vsc-little-font "-outline-ProggyTinyTT-normal-r-normal-normal-16-120-96-96-c-*-iso8859-1"))
(add-to-list 'default-frame-alist (cons 'font vsc-little-font))
(add-to-list 'initial-frame-alist (cons 'font vsc-little-font))

Related

disable autocomplete for specific filetype or language in emacs [duplicate]

I am using Emacs 24 and would like to disable auto-complete mode while in python-mode so it does not conflict with jedi. How do I go about doing this (sadly I do not know Emacs Lisp). Below are my current settings regarding auto-complete in init.el:
;; auto-complete settings
(require 'auto-complete)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(require 'auto-complete-config)
(ac-config-default)
; Start auto-completion after 2 characters of a word
(setq ac-auto-start 2)
; case sensitivity is important when finding matches
(setq ac-ignore-case nil)
Thanks.
(ac-config-default) turns on global-auto-complete-mode, to stop (auto-complete-mode) from being called in python mode you can write an advice for it.
(defadvice auto-complete-mode (around disable-auto-complete-for-python)
(unless (eq major-mode 'python-mode) ad-do-it))
(ad-activate 'auto-complete-mode)
Also I am not sure this is what you want, since Jedi use auto-complete-mode as Dmitry pointed out in the comment, there should not be conflicts.
I think I had a similar problem: my yellow Jedi popups with Python-specific content were taken over by grey popups from a more general auto-complete feature. Hence, I could choose non-Python related options, but not the Python-specific ones.
What helped for me was ensuring that auto-complete-mode is disabled in Python mode:
(add-hook 'python-mode-hook (lambda () (auto-complete-mode -1)))

emacsclient font check not working

I am trying to set my font for emacsclient like so:
(let ((default-font (cond
((member "Inconsolata" (font-family-list))
"Inconsolata 14")
(t
"monospace 20"))))
(set-default-font default-font)
(add-to-list 'default-frame-alist `(font . ,default-font)))
I C-x C-e at the cond sexp and it returns "Inconsolata 14". I C-x C-e at the let sexp and the font is updated.
When I launch emacs via
$ emacs
it works (the font is set to Inconsolata 14).
However when I launch the application via
$ emacsclient --alternate-editor="" --create-frame "$#"
the font is monospace 20 instead.
Please advise.
EDIT:
I have discovered that by including
(message "%s" (font-family-list))
in my .emacs file that (font-family-list) returns nil when emacsclient is starting up.
Unfortunately, also during initialization:
;; Both also print `nil` to the `*Messages*` buffer.
(message "%s" (find-font (font-spec :name "inconsolata")))
(message "%s" (find-font (font-spec :name "Inconsolata")))
;; Throws "error: No fonts being used"
(message "%s" (describe-font "Inconsolata"))
I do not know how to detect if a font is installed during initialization. My question has become: How do I reliably check whether a font is available when emacsclient starts up?
EDIT 2:
Echoing in after-init-hook, emacs-startup-hook, window-setup-hook, before-make-frame-hook, and after-make-frame-functions also results in nil.
Sigh... was annoyed with this problem as well, but I found the Emacs Lisp solution. Here is a straight copy/paste of the respective snippet from my Emacs configuration:
(defun frame-font-setup
(&rest ...)
;; (remove-hook 'focus-in-hook #'frame-font-setup)
(unless (assoc 'font default-frame-alist)
(let* ((font-family (catch 'break
(dolist (font-family
'("Powerline Consolas"
"Consolas for Powerline"
"Consolas"
;;
"Powerline Inconsolata-g"
"Inconsolata-g for Powerline"
"Inconsolata-g"
;;
"Powerline Source Code Pro"
"Source Code Pro for Powerline"
"Source Code Pro"
;;
"Powerline DejaVu Sans Mono"
"DejaVu Sans Mono for Powerline"
"DejaVu Sans Mono"
;;
"Monospace"))
(when (member font-family (font-family-list))
(throw 'break font-family)))))
(font (when font-family (format "%s-12" font-family))))
(when font
(add-to-list 'default-frame-alist (cons 'font font))
(set-frame-font font t t)))))
(add-hook 'focus-in-hook #'frame-font-setup)
Mmmhhh... [Rejoice]
I managed to find an answer in this post in emacs subreddit.
Here is the code snippet that I put in in init.el:
(defun rag-set-face (frame)
"Configure faces on frame creation"
(select-frame frame)
(if (display-graphic-p)
(progn
(when (member "PragmataPro" (font-family-list))
(set-frame-font "PragmataPro-13")))))
When you start Emacs as a daemon (which is done implicitly by emacsclient on-demand), the .emacs is loaded before Emacs has made a connection to any "display device" (aka "terminal"), i.e. it is not connected to any GUI nor any tty. Instead its terminal is a dummy device which reads from stdin and sends the output to stdout (well, at the beginning and soon after, even that communication link is cut), so there are no fonts there.
One way to get what you want is to do something like:
(add-to-list face-font-family-alternatives '("myfont" "Inconsolata" "Monospace"))
and then to customize the default face to use the font family myfont. You may still have problems with the size of the font, in which case you may want to play with face-font-rescale-alist.
Seems to be pretty much impossible with elisp alone so I've settled for fc-list. This works.
(let ((default-font (cond
((and
(eq system-type 'gnu/linux)
(null (string= "" (shell-command-to-string "which fc-list")))
(null (string= "" (shell-command-to-string "fc-list inconsolata"))))
"Inconsolata 14")
(t
"monospace 12"))))
(set-default-font default-font)
(add-to-list 'default-frame-alist `(font . ,default-font)))

setting up semantic with cscope

I'm starting to experiment a bit with using emacs as my development envrionment and I am running into a bit of trouble. I wish to use cscope with semantic for a fairly robust way of searching through my code base. However, after installing cscope (with apt-get install cscope) and moving xscope.el into my ~/.emacs.d/, I am still having trouble calling some settings with my .emacs file. When I try to call (semanticdb-enable-cscope-databases), I get an error that the symbol's function definition is void. I am using emacs 24.3
(semantic-mode 1)
(global-ede-mode 1)
(require 'semantic/ia)
;; Semantic
(global-semantic-idle-completions-mode t)
(global-semantic-decoration-mode t)
(global-semantic-highlight-func-mode t)
(global-semantic-show-unmatched-syntax-mode t)
;; auto-complete stuff
(add-to-list 'load-path "~/.emacs.d")
(require 'auto-complete-config)
(ac-config-default)
(add-hook 'c-mode-common-hook '(lambda ()
;; ac-omni-completion-sources is made buffer local so
;; you need to add it to a mode hook to activate on
;; whatever buffer you want to use it with. This
;; example uses C mode (as you probably surmised).
;; auto-complete.el expects ac-omni-completion-sources to be
;; a list of cons cells where each cell's car is a regex
;; that describes the syntactical bits you want AutoComplete
;; to be aware of. The cdr of each cell is the source that will
;; supply the completion data. The following tells autocomplete
;; to begin completion when you type in a . or a ->
(add-to-list 'ac-omni-completion-sources
(cons "\\." '(ac-source-semantic)))
(add-to-list 'ac-omni-completion-sources
(cons "->" '(ac-source-semantic)))
;; ac-sources was also made buffer local in new versions of
;; autocomplete. In my case, I want AutoComplete to use
;; semantic and yasnippet (order matters, if reversed snippets
;; will appear before semantic tag completions).
(setq ac-sources '(ac-source-semantic ac-source-yasnippet))
))
(require 'xcscope)
(semanticdb-enable-cscope-databases) ;;This is causing problems
;;C mode
(require 'cc-mode)
;;Color theme
(require 'color-theme)
(setq color-theme-is-global t)
(add-to-list 'load-path "/home/bob/.emacs.d/theme/ample-theme/ample-theme.el")
;;(require 'ample-theme)
(eval-after-load "color-theme"
'(progn
(color-theme-initialize)
(color-theme-jsc-dark)))
;;set font
(set-face-attribute 'default nil :family "Anonymous Pro" :height 140)
;;line numbers
(global-linum-mode 1)
(custom-set-variables '(linum-format (quote "%4d \u2502 ")))
;;treat .h files at C++
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
;; use F5 as compile
(global-set-key [(f5)] 'compile)
;; make compilation window smaller
(setq compilation-window-height 8)
Now, I really start writing an answer to be able to refine it with time. That is how far I got until now:
There are several versions of cedet.
Emacs 24.3 includes cedet-2.0. But, with respect to the bazaar version cited below it seems to be slightly outdated.
I believe that in this version cscope is supported as one of the tools in semantic-symref-tool-alist.
The variable semantic-symref-tool-alist is described in the info manual. One gets there with the key strokes C-h i g (semantic-user) Configuring SymRef.
One can see the default value of semantic-symref-tool-alist after loading semantic/symref. One of its members is:
((lambda
(rootdir)
(file-exists-p
(expand-file-name "cscope.out" rootdir)))
. cscope)
I think that this is the cscope support in in the built-in version of cedet-2.0 and no additional enabling of cscope is required (?).
The official release is cedet-1.1 from https://sourceforge.net/projects/cedet/files/cedet/cedet-1.1.tar.gz/download.
In this version the function semanticdb-enable-cscope-databases is defined in the file semantic/semanticdb-cscope.el
The bazar-version of cedet is cedet-2.0. It is available via bazaar under:
bzr checkout bzr://cedet.bzr.sourceforge.net/bzrroot/cedet/code/trunk cedet
In this version the function semanticdb-enable-cscope-databases is defined in cedet/semantic/db-cscope.el.
This file is missing in the version of cedet shipped with emacs 24.3.
Σ: That makes me believe that if you want to use your setup you should use the bazaar version of cedet-2.0.

Why Can't I use old theme style file under Emacs 24.1?

I can use my style file under 23.1, 23.4, but after I update Emacs to 24.1, I can't use the old style files. For example, one of my style files is color-theme-arjen.el. Here is the link:
https://github.com/credmp/color-theme-arjen/blob/master/color-theme-arjen.el
In my elisp file, I use following code to load the color theme:
(load-file "~/emacs/site-lisp/color-theme/master_color-theme-arjen.el")
(color-theme-arjen)
I don't know why the color theme works under Emacs 23.1 & 23.4 but just doesn't work under Emacs 24.1.
While Emacs is loading the file, Emacs gives following error:
Symbol's function definition is void: plist-to-alist
If I uncomment above code and don't load the style file, the error is dismissed.
Does anyone know why this happens? Or how can I debug it?
Yeah , I found this bug too. It seems that the Emacs 24 dosen't have the ' plist-to-alist ' function. So probably you should write it yourself. Here is mine.
Put this function in your dot-emacs file then it will be ok.
(defun plist-to-alist (the-plist)
(defun get-tuple-from-plist (the-plist)
(when the-plist
(cons (car the-plist) (cadr the-plist))))
(let ((alist '()))
(while the-plist
(add-to-list 'alist (get-tuple-from-plist the-plist))
(setq the-plist (cddr the-plist)))
alist))
Hope it helps : )
The color theme stuff was heavily revamped in 24, there is a color theme package included with emacs (see M-x customize-themes), and as far as I know breakage of older themes is expected.
The color theme package from marmalade reportedly works as well.
You should probably open a bug report for color-theme-arjen.
I have little idea why, but when installing the solarized theme in emacs 24.3.1 on MacOS X, I found that if I put my init lines:
(load-file "~/lisp/color-theme/color-theme.el")
(load-file "~/lisp/emacs-colors-solarized/color-theme-solarized.el")
(color-theme-solarized 'dark)
after I turned off the scroll bars:
(if (featurep 'scroll-bar)
(scroll-bar-mode -1))
it worked fine. The other way around, I get the error above. I've no idea why the color-theme-alist function is affected by the absence of a scroll bar (the plist-to-alist function call seems to be only for XEmacs)
I definitely thanks wenjun.yan. But i would rather want to check if the function exist before defining it :
(unless (fboundp 'plist-to-alist)
(defun plist-to-alist (the-plist)
(defun get-tuple-from-plist (the-plist)
(when the-plist
(cons (car the-plist) (cadr the-plist))))
(let ((alist '()))
(while the-plist
(add-to-list 'alist (get-tuple-from-plist the-plist))
(setq the-plist (cddr the-plist)))
alist)))

Emacs: Best-practice for lazy loading modes in .emacs?

Is there a best practice around lazily loading modes when encountering a relevant file extension?
At this point I have roughly 25 different Emacs modes installed, and startup has become slow. For example, although it's great to have clojure-mode at the ready, I rarely use it, and I want to avoid loading it at all unless I open a file with extension .clj. Such a "lazy require" functionality seems like the right way do mode configuration in general..
I found nothing online, so I've taken a crack at it myself.
Instead of:
(require 'clojure-mode)
(require 'tpl-mode)
I have this:
(defun lazy-require (ext mode)
(add-hook
'find-file-hook
`(lambda ()
(when (and (stringp buffer-file-name)
(string-match (concat "\\." ,ext "\\'") buffer-file-name))
(require (quote ,mode))
(,mode)))))
(lazy-require "soy" 'soy-mode)
(lazy-require "tpl" 'tpl-mode)
This seems to work (I'm an elisp newbie so comments are welcome!), but I'm unnerved about finding nothing written about this topic online. Is this a reasonable approach?
The facility you want is called autoloading. The clojure-mode source file, clojure-mode.el, includes a comment for how to arrange this:
;; Add these lines to your .emacs:
;; (autoload 'clojure-mode "clojure-mode" "A major mode for Clojure" t)
;; (add-to-list 'auto-mode-alist '("\\.clj$" . clojure-mode))
This is one way,
(provide 'my-slime)
(eval-after-load "slime"
'(progn
(setq slime-lisp-implementations
'((sbcl ("/usr/bin/sbcl"))
(clisp ("/usr/bin/clisp")))
common-lisp-hyperspec-root "/home/sujoy/documents/hyperspec/")
(slime-setup '(slime-asdf
slime-autodoc
slime-editing-commands
slime-fancy-inspector
slime-fontifying-fu
slime-fuzzy
slime-indentation
slime-mdot-fu
slime-package-fu
slime-references
slime-repl
slime-sbcl-exts
slime-scratch
slime-xref-browser))
(slime-autodoc-mode)
(setq slime-complete-symbol*-fancy t)
(setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol)
(add-hook 'lisp-mode-hook (lambda () (slime-mode t)))))
(require 'slime)
along with,
;; slime mode
(autoload 'slime "my-slime" "Slime mode." t)
(autoload 'slime-connect "my-slime" "Slime mode." t)