如果我要重新定义一个密钥,我应该拨打(global-unset-key (kbd "key-combo"))
,还是使用global-set-key
功能自动为我调用?
答案 0 :(得分:7)
在设置之前绝对不需要取消密钥。
这与任何编程语言中的变量设置类似:您不需要在import java.util.InputMismatchException; //added the import
import java.util.Scanner; // added the import
class NumberHighException extends Exception {
public NumberHighException() {}
public NumberHighException(String str) {
super(str);
}
public String toString() {
return "NumberHighException";
}
}
class NumberLowException extends Exception {
public NumberLowException() {}
public NumberLowException(String str) {
super(str);
}
public String toString() {
return "NumberLowException";
}
}
// negative number is a type of low number
class NumberNegativeException extends NumberLowException {
public NumberNegativeException() {}
public NumberNegativeException(String str) {
super(str);
}
public String toString() {
return "NumberNegativeException";
}
}
class Verify {
// lowest number in range
private int minimum;
// highest number in range
private int maximum;
// constructor sets minimum and maximum values in range
public Verify(int minimum, int maximum) {
this.minimum = minimum;
this.maximum = maximum;
}
// validate that number is within range
public void validate(int number)
throws NumberNegativeException, NumberLowException, NumberHighException
{
if (number < 0) throw new NumberNegativeException("number < 0");
else if (number < minimum) throw new NumberLowException("number < 10");
else if (number > maximum) throw new NumberHighException("number > 100");
}
}
public class Program5 // added the public keyword
{
public static void main(String[] args) {
int number = 0;
int returnCode = 0;
int minimum = 10;
int maximum = 100;
// create object to verify number is within range 10 to 100
Verify ok = new Verify(minimum, maximum);
// create Scanner object to read keyboard
Scanner input = new Scanner(System. in );
// prompt for input
System.out.print("Enter number between " + minimum +
" and " + maximum + ": ");
try {
// read int from keyboard
// throws exception if non digits are entered
number = input.nextInt();
} catch (InputMismatchException e) {
System.err.println("You entered a non digit");
System.exit(1);
}
// validate that entered number is within specified range
try {
ok.validate(number);
} catch (NumberHighException e) {
System.out.println("NumberHighException: " + e.getMessage());
returnCode = 2;
}
// because NumberNegativeException is subclass of NumberLowException
// it must be caught before NumberLowException or compile error results
catch (NumberNegativeException e) {
System.out.println("NumberNegativeException: " + e.getMessage());
returnCode = 3;
} catch (NumberLowException e) {
System.out.println("NumberLowException: " + e.getMessage());
returnCode = 4;
} finally {
// true is number entered was within range
if (returnCode == 0) System.out.println(number + " is valid number");
}
System.exit(returnCode);
}
}
之前执行foo = NULL
。这种比较比人们想象的更接近,因为foo = x
与(global-unset-key k)
相同。
答案 1 :(得分:3)
与sds一样,global-unset-key
实际上会调用global-set-key
:
(defun global-unset-key (key)
"Remove global binding of KEY.
KEY is a string or vector representing a sequence of keystrokes."
(interactive "kUnset key globally: ")
(global-set-key key nil))
所以实际上set和unset键之间没有真正的区别。